Mysql Multiple Update in a PHP Web Page

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I need to create a form using multiple quantities that can be updated by one
single update.

<form method="post" enctype = "multipart/formdata">
<? do { ?>
<?php echo $row_rsBasket['id']; ?>
<input name="qty" type="text" value="<?php echo $row_rsBasket['qty']; ?>"
<? } while ($row_rsBasket = mysql_fetch_assoc($rsBasket)); ?>
<input type="hidden" name="send" value="true">
<input type ="submit" name = "update" value ="update">

How do I create the multiple update when the page is submitted back to

if(isset($_POST['update']) && ($_POST['update'] == "true")){
//loop thorugh each of the submitted qty values this is where I am stuck!!
for each(){
mysql_query = "UPDATE tblCart SET qty = $_POST['qty'] WHERE id = 'ID' // not
sure how to pull out 'ID'

Any help will be grateful

Re: Mysql Multiple Update in a PHP Web Page

Craig Keightley wrote:
Quoted text here. Click to load it

   Hi Craig,

   uhm, a bit messy.

   Still didn't quite get what you are trying to do actually. You mean
update several values into a mysql row with one statement?  Something
like this:

<form method="post" target="_self">
<input type="text" value="<?php echo $somevalue; ?>" name="a">
<input type="text" value="<?php echo $othervalue; ?>" name="b">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="submit">


if ($_POST["id"]) {
   mysql_query("UPDATE INTO sometable VALUES ($_POST['id'],$_POST['a'],

if "id" is the primary key, then if it exists in the mysql table, the
row will be updated.  If not, then a new row will be created.

   Anyway, this looks like a very messy, and very hard-to-maintain way
to code.  Why not:
1) use some ready shopping cart code
2) use some ready libraries to handle form processing, db access, etc.


Re: Mysql Multiple Update in a PHP Web Page

sorry for not being thorough with th eproblem.
I'll try again

i want to be able to create a foreach loop thta creates multiple indivdual
update queries
so for each qty that is in the form, update the row in the table accordingly

i  hope this makes a bit more sense


Quoted text here. Click to load it

Site Timeline