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.
<form method="post" action="update.php">
<?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"<input type=\"hidden\" name=\"id\" value=" . $row['id'] . " />";
echo"<input type=\"text\" name=\"fname\" value=" . $row['fname'] . " />";
echo"<input type=\"text\" name=\"lname\" value=" . $row['lname'] . " />";
}
?>
<input type="submit" value="Save Changes" />
<?php
$sql = "UPDATE list SET fname = '{$fname}', lname = '{$lname}' WHERE id = {$id}";
$result = mysql_query( $sql );
?>
</form>