Jump to content

POST array and receiving


kirkh34

Recommended Posts

i have a shopping cart set up with mysql with a $_COOKIE['cart_id'] used to call all rows with cart_id... i have a while loop print out all the items in the cart

 

$sql2 = mysql_query("SELECT * FROM cart WHERE cart_id = '$cart_id'")
or die(mysql_error());
while($row = mysql_fetch_array($sql2)){

 

 

then i have it echo out the name...desc... quantity of each item... but the quantity is set up to be able to change and i have a form set up and i'd like to have each item be able to be changed at once if they wanted....but being multiple rows... there could be multiple $_POST['quantity']...

 

echo "<td><input type='text' name='quantity' value='".$quantity."'/></td>";

 

 

there is a unique id for each row in the table that i'd like to set up with an array to post... i'd like to set up an array

$array[$uniq_id] => $quantity;

and somehow POST this array name='$array[]'

 

and then on the action end... be able to call it by having

foreach($quantity  as $uniq_id => $qty){
mysql_query("UPDATE cart SET quantity='$qty' WHERE id='$uniq_id' ");

}

 

i'm not sure if i'm approaching this the right way... the array part is leaving me stuck...any help is appreciated..thank you!

Link to comment
Share on other sites

change form part to

echo "<td><input type='text' name='quantity[".$uniq_id."]' value='".$quantity."'/></td>";

and on action page do

foreach($_POST['quantity']  as $uniq_id => $qty){
mysql_query("UPDATE cart SET quantity='$qty' WHERE id='$uniq_id' ");

}

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.