title: Multiple update buttons on single form
body: <p>Please forgive me for the terribly structured code. I'm attempting to update different customers on each line with an individual submit button. The delete function works great. I'm trying to pass the ID of the row when the submit button is clicked for each row. However, I'm getting the ID for the last row, no matter which row I click. I've attached a screenshot as an example. Any help is appreciated!</p>
  
  <p><img src="https://i.imgur.com/DGYi5FU.png" alt="Screenshot of output">   </p>
  
  <pre><code> &lt;form action="" method="post"&gt;
   &lt;table class="table table-striped table-bordered table-responsive"&gt;
  &lt;thead&gt;
  &lt;tr&gt;
  &lt;th&gt;Name&lt;/th&gt;
  &lt;th&gt;Email&lt;/th&gt;
  &lt;th&gt;Phone&lt;/th&gt;
  &lt;th&gt;Address&lt;/th&gt;
  &lt;th&gt;Product&lt;/th&gt;
  &lt;th&gt;Firmware Version&lt;/th&gt;
  &lt;th&gt;Purchase Date&lt;/th&gt;
  &lt;th&gt;Delete&lt;/th&gt;
  &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;?php
  $pdo = new PDO("mysql:host=localhost;dbname=project", $username, $password, array(
  PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION
  ));
  $query = $pdo-&gt;prepare("select * from customers");
  $query-&gt;execute();
  while($customers = $query-&gt;fetch()){
  $ID = $customers['ID'];
  echo '&lt;tr&gt;&lt;td&gt;&lt;input type="text" name="name" value="';
  echo $customers['name'];
  echo '"&gt;&lt;/td&gt;';
  echo "&lt;td&gt;" . $customers['email'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $customers['phone'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $customers['address'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $customers['product'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $customers['firmware'] . "&lt;/td&gt;";
  echo "&lt;td&gt;" . $customers['purchase_date'] . "&lt;/td&gt;";
  echo '&lt;td align="center"&gt;&lt;input type="hidden" name="id" value="';
  echo $ID;
  echo '"&gt;&lt;input type="submit" name="delete" value="X"&gt; &lt;/td&gt;&lt;/tr&gt;';
  echo '&lt;tr&gt;&lt;td colspan="8"&gt;&lt;input type="hidden" name="id_update" value="';
  echo $ID;
  echo '"&gt;&lt;input type="submit" name="update" value="Update"&gt;';
  echo $ID . '&lt;--This is the ID for each row';
  echo '&lt;/td&gt;&lt;/tr&gt;';
  }
  
  // Delete customer
  if(isset($_POST['delete'])) {
  
  try{
  $ID = $_POST['id'];
  $query = $pdo-&gt;prepare("delete from customers where ID = :ID");
  $query-&gt;bindParam(':ID', $ID);
  $query-&gt;execute(array(
  ':ID' =&gt; $ID
  ));
  echo "Customer successfully deleted.";
  echo '&lt;META http-equiv="refresh" content="1;URL=view_edit.php"&gt;';
  }catch(PDOException $e){
  echo "Failed to delete the MySQL database table ... :".$e-&gt;getMessage();
  } //end of try
  } //end of isset delete
  
  
  // Edit customer
  if(isset($_POST['update'])) {
  echo "Update " . $_POST['id_update'] . '&lt;-- This is the result of clicking update for each row';
  } //end of isset update
  
  ?&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>