I am willing to create a Shop Cart using simple PHP SESSION ARRAY. I tried to search different StackOverFlow problems, but none of those is giving me exact solution of my problem. Maybe I am doing any silly mistake. However,
I am doing this:
<!-- SHOPPING CART -->
<?php
if(isset($_REQUEST['atc']))
{
$item = $_REQUEST['atc'];
$_SESSION['cart'] = array();
array_push($_SESSION['cart'], $item);
//$_SESSION['cart'][] = $item;
foreach($_SESSION["cart"] as $key => $val)
{
echo $key . ">" . $val;
}
}
?>
<!-- SHOPPING CART -->
I am receiving $_REQUEST['ate'] (Integer Value/Product ID) when User is Clicking "ADD TO CART" Button on the same page. Then I am putting the value in $item, then I am declaring $_SESSION['cart'] as Array. Then I have tried array_push, and even tried $_SESSION['cart'][] to Push Integer Value. But each time only the first element is updated, therefore $_SESSION['cart'][0] is storing the value, not $_SESSION['cart'][1] or the rest.