Hello,
I'm hoping someone can help me out here.
I'm building a shopping cart using sessions, populating with $_POST
values from a form. Code abbreviated below:
check if form is submitted. if so, set up variables:
$name = $_POST['name'];
$ribbon = $_POST['ribbon'];
$quantity = 1;
if (isset($_SESSION['cart'][$item_id])) $item_id = ($item_id+1);
else $item_id = 1;
now, add those values to cart array:
$_SESSION['cart'][]= array( 'name' =$name, 'ribbon' =$ribbon,
'quantity' =$quantity, 'item_id' =$item_id);
$cart = $_SESSION['cart'];
This is working mostly so far. Problem is, assigning an 'item id' to
each item in the array is failing. I'll need this later to allow
users to update quantities,delete, etc. from the cart. I'm thinking
that I'd do well to assign the array numbers (0 and 1 as shown in cart
array structure below) as an 'item id' in each item's array.
Unfortunately, I can't figure out how to do this. You'll see below
that each array's 'item_id" is getting stuck at 1. Anyone out there
have any suggestions? Thanks so much in advance, Chris.
Array
(
[0] =Array
(
[name] =Bob
[ribbon] =green multi
[quantity] =1
[item_id] =1
)
[1] =Array
(
[name] =Sally
[ribbon] =blue multi
[quantity] =1
[item_id] =1
)
)