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
https://forums.phpfreaks.com/topic/219237-post-array-and-receiving/
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' ");

}

Archived

This topic is now archived and is closed to further replies.

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