🙂 Hi everyone, ive got a little problem with my code.
Im trying to create a basic shopping cart but i am getting confused on the section of how to update the product if it already exist. I think ive got the add new product bit right.
I'm not sure how to set the $id so its in the right place. Could some please show me, thanks in advance!!
<?php
session_start();
if (isset($POST['submit']) && $POST['submit'] == 'add')
{
$productid = trim($POST['productid']);
$quantity = trim($POST['quantity']);
$size = trim($_POST['size']);
if ($productid)
{
if (isset($session['cart'][$id]['product']))
{
$session['cart'][$id]['productid'] = $productid;//i think i should delete this one as it wont need updating
$session['cart'][$id]['quantity'] = $quantity;
$session['cart'][$id]['size'] = $size;
}
else
{
$id = count($session['cart'];
$id++;
$session['cart'][$id]['productid'] = $productid;
$session['cart'][$id]['quantity'] = $quantity;
$session['cart'][$id]['size'] = $size;
}
}
}
?>