Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Session array not updating
i am trying to build a simple online shopping cart. Been strugling with 2 dimensional sessions array and when i finally got it working the session array is not updating.
I want to be able to browse through each product page and keep adding the productid,quantity to $_session[cart].
But each time i add to cart the previous product ids and quantities are deleted from the session. Am i doing it correctly.
Somebody please help.Thanks in advance.
Here is my code:
foreach($_POST as $var => $value)
if($value != '')
// add to session
$_SESSION['cart'][$var] = $value;
foreach($_SESSION['cart'] as $pid => $qty)
echo "Product id: $pid, Quantity:$qty ";
0 · ·