title: Delete button not returning correct values to delete query
body: <p>I have a table which displays data drawn from 2 different tables in mysql.The table has a delete button on each row which, when pressed, would send run a delete query which would delete the row, and all it's associated data from the database.</p>
  
  <p>However,no matter which delete button i click, it is always the last row in the table that is deleted, and not the row which the delete button is in.</p>
  
  <p>My table:</p>
  
  <pre><code>-------------------------------------------
  |Username|Password|Branch Name|Branch Info|
  ----------------------------------------------------
  |Sub1    |Pass1   |branch1    |1st branch |DELETE  |
  ----------------------------------------------------
  |Sub2    |Pass2   |branch2    |2nd branch |DELETE  |&lt;---this button is pressed
  ----------------------------------------------------
  |Sub3    |Pass3   |branch3    |3rd branch |DELETE  |
  ----------------------------------------------------
  |Sub4    |Pass4   |branch4    |4th branch |DELETE  |
  ----------------------------------------------------
  |Sub5    |Pass5   |branch5    |5th branch |DELETE  |&lt;---this row is deleted.
  ----------------------------------------------------
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>&lt;?PHP
  session_start();
  
  if(@$_SESSION['Auth']!=="Yes" AND @$_SESSION['Type']!=="Admin")
  {
  echo"You are not authorised to view this page.Please click &lt;a href='Login.php'&gt;here&lt;/a&gt; to login.";
  exit();
  }
  ?&gt;
  
  &lt;?PHP
  
  if(@$_POST['deluser']=="Delete")
  {
  include("cxn.inc");
  print_r($_POST);
  $id="$_POST[id]";
  echo"$id";
  if(empty($_POST["id"]))
  echo"yep";
  $deluser="DELETE FROM SubUsers WHERE SubUsers.id='$id'";
  $delquery=mysqli_query($cxn,$deluser) or die (mysqli_error($cxn));
  $delsuccess="Deletion successful";
  }
  &gt;
  
  &lt;html&gt;
  &lt;head&gt;&lt;link rel="stylesheet" type="text/css" href="style.css" /&gt;&lt;/head&gt;
  &lt;body&gt;
  
  
  &lt;?PHP
  include("cxn.inc");
  //include("AdminNav.php");
  $viewuser="SELECT SubUsers.Id,Username,Password,Name,Info FROM SubUsers,Branch WHERE SubUsers.id=Branch.id AND SubUsers.Userid='$_SESSION[UserId]'";
  $runuser=mysqli_query($cxn,$viewuser) or die(mysqli_error($cxn));
  $rows=array();
  while($row=mysqli_fetch_assoc($runuser))
  $rows[]=$row;
  echo"&lt;form action='$_SERVER[PHP_SELF]' name='DelUser' method='POST' &gt;";
  echo"&lt;table border='1'&gt;";
  echo"&lt;tr&gt;";
  echo"&lt;td&gt;";
  echo"Username";
  echo"&lt;/td&gt;";
  echo"&lt;td&gt;";
  echo"Password";
  echo"&lt;/td&gt;";
  echo"&lt;td&gt;";
  echo"Branch Name";
  echo"&lt;/td&gt;";
  echo"&lt;td&gt;";
  echo"Branch Info";
  echo"&lt;/td&gt;";
  echo"&lt;/tr&gt;";
  foreach($rows as $row)
  {
  $id=$row['Id'];
  echo"$id";
  echo"&lt;tr&gt;";
  echo"&lt;td&gt;";
  echo"$row[Username]";
  echo"&lt;/td&gt;";
  echo"&lt;td&gt;";
  echo"$row[Password]";
  echo"&lt;/td&gt;";
  echo"&lt;td&gt;";
  echo"$row[Name]";
  echo"&lt;/td&gt;";
  echo"&lt;td&gt;";
  echo"$row[Info]";
  echo"&lt;/td&gt;";
  echo"&lt;td&gt;";
  echo"&lt;input type='hidden' name='id' value='$id' &gt;";
  echo"&lt;input type='Submit' name='deluser' value='Delete' &gt;";
  echo"&lt;/td&gt;";
  echo"&lt;/tr&gt;";
  }
  echo"&lt;tr&gt;";
  echo"&lt;td colspan='5'&gt;";
  if(isset($delsuccess))
  {echo"$delsuccess";}
  
  echo"&lt;/td&gt;";
  echo"&lt;/tr&gt;";
  echo"&lt;/table&gt;";
  echo"&lt;/form&gt;";
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The line</p>
  
  <p>echo"$id";</p>
  
  <p>under the foreach loop successfully returns the id of each row correctly as each row is being output to the screen.</p>
  
  <p>Upon pressing the DELETE Button, the line</p>
  
  <pre><code>print_r($_POST);
  </code></pre>
  
  <p>outputs all variables in $_POST, which gives the result</p>
  
  <pre><code>Array ( [id] =&gt; x [deluser] =&gt; Delete ) 
  </code></pre>
  
  <p>where x is the id of the last row in the table(E.g if there are 5 rows in the table, x=5)</p>
  
  <p><em><strong>QUESTION</em></strong>
  Why does the DELETE button keep passing the id of the last row only, and not the id of the row it's on?Also, how and what do i have to do to make it so that when the delete button is pressed, only the row beside the delete button is deleted?</p>
  
  <p>I've been looking at this for the past 2 hours and still can't figure out where i'm wrong; the code is obviously working as rows are being deleted when the delete buton is pressed, however it's just that the WRONG rows are being deleted.</p>
  
  <p>Any help would be greatly appreciated.
  Thanks</p>