By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,604 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

Mysql Multiple Update in a PHP Web Page

P: n/a
I need to create a form using multiple quantities that can be updated by one
single update.
eg:
(HTML PAGE)
<form method="post" enctype = "multipart/formdata">
<? do { ?>
<?php echo $row_rsBasket['id']; ?>
<input name="qty" type="text" value="<?php echo $row_rsBasket['qty']; ?>"
size="3">
<? } 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
itself?

(TOP OF THE HTML PAGE)
<?
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
Craig

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Craig Keightley wrote:
....
How do I create the multiple update when the page is submitted back to
itself?

(TOP OF THE HTML PAGE)
<?
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'
}
}
?>


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">
</form>

....

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

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.

/Marcin
Jul 17 '05 #2

P: n/a
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

craig

"Marcin Dobrucki" <Ma*************@TAKETHISAWAY.nokia.com> wrote in message
news:uc*****************@news1.nokia.com...
Craig Keightley wrote:
...
How do I create the multiple update when the page is submitted back to
itself?

(TOP OF THE HTML PAGE)
<?
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'
}
}
?>


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">
</form>

...

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

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.

/Marcin

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.