Hello,

I'm working on a shopping cart using an array stored in a session. i've got it working so that I can add a product to it but when I add a second product it overwrites the existing item. I think it must be something to do with needing nesting arrays?

Please can anyone help?

my code so far is:

if ($POST['id']=="")
{}
else
{
if(isset($
SESSION['cart']))
{
$SESSION['cart'] = array("item1" => array("prodId" => $id,
"prodName" => $prod,
"prodSize" => $size,
"prodPrice" => $price,
"prodBrand" => $brand,
"prodQty" => 1));
$
SESSION['cart'];
}
else
{
$_SESSION['cart'] = array("prodId" => $id,
"prodName" => $prod,
"prodSize" => $size,
"prodPrice" => $price,
"prodBrand" => $brand,
"prodQty" => 1);
}
}

    If you're putting array's into SESSION variables you need to serialize them.

      thanks for your reply, although i'm not sure what you mean. can you give me an example?

        $anarray=array('var1','var2','var3');
        $_SESSION['arrayvar']=serialize($anarray);
        
          Write a Reply...