title: Admin panel script not functioning properly
body: <p>The script is as follows...</p>
  
  <pre><code>&lt;?php
  
  // ########## GAME UPDATE FORM ##########
  
  if (isset($_GET['tab']) &amp;&amp; $_GET['tab'] === 'gameupdates') {
  
  $delete = 'update';
  
  if (isset($_SESSION['success'])) {
  
      echo $_SESSION['success'];
      unset($_SESSION['success']);
  }
  
  echo '&lt;p&gt;To make a new game update fill out the form below along with the type of update it corresponds to.&lt;/p&gt;&lt;p&gt;If you have completed a task make sure to remove it from the &lt;a href="/adminpanel?tab=tasklist"&gt;task list&lt;/a&gt;.&lt;/p&gt;&lt;form action="/adminpanel?tab=process" method="post"&gt;
  &lt;fieldset&gt;
  &lt;input type="hidden" name="newupdate" /&gt;
  &lt;textarea name="message"&gt;&lt;/textarea&gt;
  &lt;select name="type"&gt;
      &lt;option value="Community"&gt;Community&lt;/option&gt;
      &lt;option value="Security"&gt;Security&lt;/option&gt;
      &lt;option value="Gameplay"&gt;Gameplay&lt;/option&gt;
      &lt;option value="Account"&gt;Account&lt;/option&gt;
      &lt;option value="Miscellaneous"&gt;Misc.&lt;/option&gt;
  &lt;/select&gt;
  &lt;input id="submit" type="submit" value="Insert Update" /&gt;
  &lt;/fieldset&gt;
  &lt;/form&gt;&lt;p&gt;The last six updates were as follows from newest to oldest:&lt;/p&gt;&lt;p&gt;(To delete an entry hover over the update and press delete)&lt;/p&gt;';
  
  $q = $dbc -&gt; prepare ("SELECT * FROM updates ORDER BY date_time DESC LIMIT 0, 6");
  $q -&gt; execute();
  
      while ($update = $q -&gt; fetch(PDO::FETCH_ASSOC)) {
  
          echo '&lt;div id="displaybox"&gt;&lt;div&gt;&lt;strong&gt;' . $update['date_time'] . '&lt;/strong&gt;&lt;span&gt;' . $update['type'] . '&lt;/span&gt;&lt;/div&gt;&lt;p&gt;' . $update['message'] . '&lt;/p&gt;&lt;a href="/adminpanel?tab=process&amp;update=' . $update['date_time'] . '"&gt;Delete&lt;/a&gt;&lt;/div&gt;';
      }
  }
  
  // ########## TO DO LIST ##########
  
  elseif (isset($_GET['tab']) &amp;&amp; $_GET['tab'] === 'tasklist') {
  
  $delete = 'task';
  
  if (isset($_SESSION['success'])) {
  
      echo $_SESSION['success'];
      unset($_SESSION['success']);
  }
  
  echo '&lt;p&gt;This is the to do list anything that needs to be done whether it be urgent or not put it here.&lt;/p&gt;&lt;p&gt;Remember once the task has been completed remember to add it to the &lt;a href="/adminpanel?tab=gameupdates"&gt;game updates&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Below (if any) are the current tasks that need doing, to add a new task complete the form at the bottom of this page.&lt;/p&gt;';
  
  $q = $dbc -&gt; prepare ("SELECT * FROM tasks ORDER BY date_time");
  $q -&gt; execute();
  
      while ($task = $q -&gt; fetch(PDO::FETCH_ASSOC)) {
  
          echo '&lt;div id="displaybox"&gt;&lt;div&gt;&lt;strong&gt;' . $task['date_time'] . '&lt;/strong&gt;&lt;span&gt;' . $task['type'] . '&lt;/span&gt;&lt;/div&gt;&lt;p&gt;' . $task['message'] . '&lt;/p&gt;&lt;a href="/adminpanel?tab=process&amp;task=' . $task['date_time'] . '"&gt;Delete&lt;/a&gt;&lt;/div&gt;';
      }
  
  echo '&lt;p&gt;To add a task complete the form below, along with which type of update it is.&lt;/p&gt;&lt;p&gt;To delete a task once it has been completed hover over the task and press delete.&lt;/p&gt;&lt;form action="/adminpanel?tab=process" method="post"&gt;
  &lt;fieldset&gt;
  &lt;input type="hidden" name="newtask" /&gt;
  &lt;textarea name="message"&gt;&lt;/textarea&gt;
  &lt;select name="type"&gt;
      &lt;option value="Community"&gt;Community&lt;/option&gt;
      &lt;option value="Security"&gt;Security&lt;/option&gt;
      &lt;option value="Gameplay"&gt;Gameplay&lt;/option&gt;
      &lt;option value="Account"&gt;Account&lt;/option&gt;
      &lt;option value="Miscellaneous"&gt;Misc.&lt;/option&gt;
  &lt;/select&gt;
  &lt;input id="submit" type="submit" value="Insert New Task" /&gt;
  &lt;/fieldset&gt;
  &lt;/form&gt;';
  }
  
  // ########## PROCESS ADMIN CHANGES ##########
  
  elseif (isset($_GET['tab']) &amp;&amp; $_GET['tab'] === 'process') {
  
  // ########## GAME UPDATE SUCCESS ##########
  
  if (isset($_POST['newupdate'])) {
  
      if ($_POST['message'] === '') {
          header('Location:/adminpanel?tab=gameupdates');
          exit();
              }
  
      $q = $dbc -&gt; prepare("INSERT INTO updates (message, type, date_time) VALUES (?, ?, ?)");
      $q -&gt; execute(array($_POST['message'], $_POST['type'], date("y/m/d : H:i:s", time())));
      $_SESSION['success'] = '&lt;p&gt;&lt;strong&gt;Successfully added a new game update.&lt;/strong&gt;&lt;/p&gt;';
      header('Location:/adminpanel?tab=gameupdates');
      exit();
  }
  
  // ######### TO DO LIST SUCCESS ##########
  
  elseif (isset($_POST['newtask'])) {
  
      if ($_POST['message'] === '') {
          header('Location:/adminpanel?tab=tasklist');
          exit();
      }
  
      $q = $dbc -&gt; prepare("INSERT INTO tasks (message, type, date_time) VALUES (?, ?, ?)");
      $q -&gt; execute(array($_POST['message'], $_POST['type'], date("y/m/d : H:i:s", time())));
      $_SESSION['success'] = '&lt;p&gt;&lt;strong&gt;Successfully added a new task.&lt;/strong&gt;&lt;/p&gt;';
      header('Location:/adminpanel?tab=tasklist');
      exit();
  }
  
  // ########## GAME UPDATE DELETE ##########
  
  elseif ($delete = 'update') {
  
      $q = $dbc -&gt; prepare("DELETE FROM updates WHERE date_time = ?");
      $q -&gt; execute(array($_GET['update']));
      $_SESSION['success'] = '&lt;p&gt;&lt;strong&gt;Successfully deleted the selected update.&lt;/strong&gt;&lt;/p&gt;';
      header('Location:/adminpanel?tab=gameupdates');
      exit();
  }
  
  // ########## TO DO LIST DELETE ##########
  
  elseif ($delete = 'task') {
  
      $q = $dbc -&gt; prepare("DELETE FROM tasks WHERE date_time = ?");
      $q -&gt; execute(array($_GET['task']));
      $_SESSION['success'] = '&lt;p&gt;&lt;strong&gt;Successfully deleted the selected task.&lt;/strong&gt;&lt;/p&gt;';
      header('Location:/adminpanel?tab=tasklist');
      exit();
  }
  
  else {
  
      header('Location:/adminpanel');
      exit();
  }
  }
  
  // ########## ADMIN CONTROL PANEL ##########
  
  else {
  echo '&lt;p&gt;This is the admin panel. Click on an option below to begin.&lt;/p&gt;&lt;p&gt;&lt;a href="/adminpanel?tab=gameupdates"&gt;Add/Remove A Game Update&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="/adminpanel?tab=tasklist"&gt;Add/Remove A Task From List&lt;/a&gt;&lt;/p&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>A long script I know, but you need to see it all for it to make sense, the script works fine apart from one little bug.</p>
  
  <p>You will notice that the first if statement has a variable </p>
  
  <pre><code>$delete = 'update';
  </code></pre>
  
  <p>Which means that if the <code>$_GET['tab'] = gameupdates</code>, <code>$delete = 'update'</code></p>
  
  <p>The second elseif is different...</p>
  
  <pre><code>if $_GET['tab'] = tasklist, $delete = 'task'
  </code></pre>
  
  <p>In these first two if and else if statements there are while loops which contain a link something like</p>
  
  <pre><code>&lt;a href="adminpanel?tab=process&amp;update OR task=' . some variable . '"&gt;Delete&lt;/a&gt;
  </code></pre>
  
  <p>Now the link is either update if it is in the <code>$_GET['gameupdates']</code> or task if it is in <code>$_GET['tasklist']</code>.</p>
  
  <p>In the third elseif statement where <code>$_GET['tab'] = process</code>, the first two statements are for the form submissions, but the last two elseif statements are what the links that I explained are for.</p>
  
  <p>Now if someone clicks the link 'Delete' while in the <code>$_GET['tab'] = updates</code>, <code>$delete = update</code>. So the second elseif statement in the elseif <code>$_GET['tab'] = process</code> fires, and it does.</p>
  
  <p>The thing is if someone clicks a link while in <code>$_GET['tab'] = tasklist</code>, then <code>$delete = task</code>. So the third elseif statement in the elseif statement <code>$_GET['tab'] = process</code>, should fire as <code>$delete = task</code>. </p>
  
  <p>Instead the update one fires all the time, and the query fails, you will notice that after the query the header redirects to the previous page with a session containing confirmation of the action. When I click the link in 'Delete' in <code>$_GET['tab'] = tasklist</code>, it fires the one for update, when it should fire the one for the <code>$_GET['tab'] = tasklist</code>.</p>
  
  <p>I hope this makes sense I am stuck as what to do, all my rules I think are correct, I cannot see my mistake...</p>
  
  <p>Thanks for your patience (and a lot of it!!!)</p>