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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.