title: PHP & MySQL update query only ever updates the last record in the table
body: <p>I have a HTML form which I am using to update a MySQL table via a post script - however, I am having an issue where the update buttons which are on each row only ever work for the last row in the table.</p>
  
  <pre><code>&lt;?php
  
  $link = mysql_connect ('localhost', 'root', 'password');
  mysql_select_db ('cardatabase');
  
  $select = 'SELECT * from cars';
  $result = mysql_query($select, $link);
  
  if(isset($_POST['update'])){
      $updatequery = "UPDATE cars SET 
          ID='$_POST[id]',
          CARMAKE='$_POST[carmake]',
          CARMODEL='$_POST[carmodel]',
          FUELTYPE='$_POST[fueltype]',
          TRANSMISSION='$_POST[transmission]',
          DOORS='$_POST[doors]',
          AMOUNT='$_POST[amount]',
          AVAILABLE='$_POST[available]'
          WHERE ID='$_POST[hidden]'";
  
      mysql_query($updatequery, $link);
  };
  
  echo '&lt;table&gt;&lt;form action=update.php method=post&gt;';
  echo '&lt;tr&gt;&lt;td&gt;ID&lt;/td&gt;&lt;td&gt;Make&lt;/td&gt;&lt;td&gt;Model&lt;/td&gt;&lt;td&gt;Fuel Type&lt;/td&gt;&lt;td&gt;Transmission&lt;/td&gt;&lt;td&gt;Engine Size&lt;/td&gt;&lt;td&gt;Doors&lt;/td&gt;&lt;td&gt;Amount&lt;/td&gt;&lt;td&gt;Available&lt;/td&gt;&lt;/tr&gt;';
  
  
  
  while($row = mysql_fetch_array($result)) {
      echo '&lt;tr&gt;';
      echo "&lt;td&gt;&lt;input type='text' name='id' value='{$row['ID']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='text' name='carmake' value='{$row['CARMAKE']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='text' name='carmodel' value='{$row['CARMODEL']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='text' name='fueltype' value='{$row['FUELTYPE']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='text' name='transmission' value='{$row['TRANSMISSION']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='text' name='enginesize' value='{$row['ENGINESIZE']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='text' name='doors' value='{$row['DOORS']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='text' name='amount' value='{$row['AMOUNT']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='text' name='available' value='{$row['AVAILABLE']}'&lt;/td&gt;";
      echo "&lt;td&gt;&lt;input type='hidden' name='hidden' value='{$row['ID']}'&lt;/td&gt;";
      echo '&lt;td&gt;&lt;input type="submit" name="update" value="Update"&lt;/td&gt;';
      echo '&lt;/tr&gt;';
  }
  
  echo '&lt;/form&gt;&lt;/table&gt;';
  mysql_close ($link);
  </code></pre>
  
  <p><code>cars</code> table:</p>
  
  <p><img src="https://i.stack.imgur.com/duVAq.png" alt="MySQL table"></p>