Jump to content

PHP update with while loop


MattD00

Recommended Posts

I created a form that would display all the information that was in my database within a textbox using a while loop. The infomation is able to be displayed but when trying to update only the information in the last textbox gets updated and the other textboxes will just stay the same.

 

<?php include ('connection.php');
?>

<form method="post" action="update.php">
<?php
$display = mysql_query("SELECT * FROM book ORDER BY id asc") or die("Table Error");

$ID = $_POST['id'];
$Title = $_POST['title'];
$Cost = $_POST['cost'];
$Stock = $_POST['stock'];

while ($row = mysql_fetch_assoc($display))
{
echo "ID :<input type=\"text\" name=\"".id."\" value = \"". $row['id'] ."\"/readonly>";
echo "Title :<input type=\"text\" name=\"".title."\" value = \"" . $row['title'] . "\"/>";
echo "Cost :<input type=\"text\" name=\"".cost."\" value = \"" .$row['cost'] . "\"/>";
echo "Stock :<input type=\"text\" name=\"".stock."\" value = \"" . $row['stock'] . "\"/>";

mysql_query("UPDATE book SET title = '" .$Title. "', cost = '" .$Cost. "', stock = '" .$Stock. "' WHERE id = '" .$ID. "'");
}
?>
<input type="submit" name="update" value="Update" />

 

Im not sure why it is doing this if someone could tell me it would be a big help

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/227761-php-update-with-while-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.