Form -> Shopping Cart updating.
Posted: Sat Jun 30, 2007 9:18 pm
I have a form that has values for each item like this:
For the quantity the name is qty(item number) and value equals the amount.
For the remove the name is remove(item number).
The cart is in a $_SESSION like this: 1,1 for the above HTML
a fulled cart would be 1,1,2,2,5,7,7
Now my question is how can I make it so it updates the quantity and removes all of the items from the cart.
I already have this so far, plus more that doesn't work and is badly designed.
Code: Select all
<input type="text" name="qty1" value="2" size="4" maxlength="4" title="Order Quantity" />
<input type="checkbox" name="remove1" value="true">For the remove the name is remove(item number).
The cart is in a $_SESSION like this: 1,1 for the above HTML
a fulled cart would be 1,1,2,2,5,7,7
Now my question is how can I make it so it updates the quantity and removes all of the items from the cart.
I already have this so far, plus more that doesn't work and is badly designed.
Code: Select all
$qty = array();
$remove = array();
foreach ( $_POST as $key => $value ) {
if(substr($key, 0, 6)=='remove'){
if($value=='true'){
$remove[] = substr($key, 6);
}
} elseif(substr($key, 0, 3)=='qty'){
$qty[] = array(substr($key, 3),$value);
}
}