question about an declaring array

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Hello group,

I'm trying to implement a shopping cart and currently have a problem
as following. First, I will explain. Consider a page as "products.php"

This page has a list of products such as:

product name                price                 button (for each

       A                             8.00
Add_to_Cart button
       B                             8.00
Add_to_Cart button
       C                            12.00
Add_to_Cart button

In this page (product.php) : I have wrapped up the "Add to car" button
in a form where it takes the product id and category id of the product
to a "add2cart.php" using POST method.

<form action="addtocart.php" method="post">
      <input type="hidden" name="productid" value="<?php echo
htmlentities($productid); ?>" />
       <input type="hidden" name="categoryid" value="<?php echo
htmlentities($selected_category); ?>" />
      <input type="submit" value="Add to Cart" />

In add2car.php I have:


   $_SESSION['order'][]= array("order" => array(
       'categoryid' => $_POST['categoryid'],
    'productid' => $_POST['productid'],
    'quantity' => ????  )

Ok, the problem is that I don't know how to keep adding added product
into the SESSION array or don't know how to append it to pre-existing
data in $SESSION[].  Currently, If I add the 2nd item the previous
item is replaced.

Sometimes user adds product A  and then he/she  adds it later on and I
need to keep track of quantity of a specific added item in cart.

1) is the array declared properly base on what I need? how to append
to the array?
2) how to increment the quantify of select product if already exists
in the array?


Re: question about an declaring array

I think I'd have a quantity field and then do

$_SESSION['order'][]= array(
'categoryid' => $_POST['categoryid'],
'productid' => $_POST['productid'],
'quantity' =>  $_POST['quantity'] );

Geoff Berrow  0110001001101100010000000110

Site Timeline