title: PHP MySQL update only updating one row
body: <p>I have set up an update query which will update values entered into text fields on a while loop. This works fine until multiple data is being looped from the database. Then for some reason only the last data in the loop will be updated and the rest will stay the same.</p>
  
  <pre><code>    &lt;form method="post" action="update.php"&gt;
      &lt;?php
      $id = $_POST["id"];
      $fname = $_POST["fname"];
      $lname = $_POST["lname"];
  
     $query= "SELECT * FROM list ORDER BY id ASC" ;
     $result= mysql_query($query);
     while($row = mysql_fetch_assoc($result) ){
     echo"&lt;input type=\"hidden\" name=\"id\" value=" . $row['id'] . " /&gt;";
     echo"&lt;input type=\"text\" name=\"fname\" value=" . $row['fname'] . " /&gt;";
     echo"&lt;input type=\"text\" name=\"lname\" value=" . $row['lname'] . " /&gt;";
   }
  ?&gt;
    &lt;input type="submit" value="Save Changes" /&gt;
  
   &lt;?php
   $sql = "UPDATE list SET fname = '{$fname}', lname = '{$lname}' WHERE id = {$id}";
  
    $result = mysql_query( $sql );
   ?&gt;
  &lt;/form&gt;
  </code></pre>