Re: Update multiple records from a text field

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kaizer Boab wrote:

Hi everybody,

I have built a shopping cart using tables. I am able to add items and remove
items from the cart. The problem I am having is updating the quantities in
the cart.

When users view the cart they can see the quantity in a text field. I want
to allow users to type in the quantities they want in this box and then
submit the form to display the new quantities.

The problem is when the form is submitted only one of the quantity fields is
updated, the others remain unchanged.  I have tried to use a while loop to
make it update all the quantities but it doesn't seem to work. Below is the
script I am using to UPDATE the quantites. Can anyone help me?

Thanx in advance.


<?php $trackerId = $HTTP_POST_VARS['trackerId']; $albumId = $HTTP_POST_VARS['albumId']; $qty = $HTTP_POST_VARS['qty'];

mysql_select_db($database_con_ayrsrock, $con_ayrsrock);

$queryQty= "SELECT qty FROM cart WHERE trackerId = $trackerId AND albumId =
$albumId";
$rsQty = mysql_query($queryQty);

while ($row_rsQty = mysql_fetch_array($rsQty))
{
$newQty = $qty;
mysql_query("update cart set qty = $newQty where trackerId = $trackerId and
albumId = $albumId");
}
; ?>

Looks like you're naming all of your quantity text boxes "qty". You need to use different var names to make multuple values come back. For instance you could use "qty[]" to have the results come back in an array. Or you could use qty[x] where x is a specific # so that you know which product to update.


--
paperCrane <Justin Patrin>

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux