I am trying to implement a 'shopping cart' where, if the 'Add to Cart' has been clicked, the respective item is either added to the cart or incremented by one if already present. However, the following code isn't working and giving me a "Cannot use a scalar value as an array" error. Any help would be highly appreciated.
if (isset($_POST['fan']) && ($_POST['fan']=="Add to Cart")) {
if (($_SESSION['cart']['fan']==0) || (!isset($_SESSION['cart']['fan']))) {
$_SESSION['cart']['fan']=1;
} else {
$_SESSION['cart']['fan']++;
}
}
cartelement, it will only produce anundefined indexnotice. You must have some other code that is causing the error. Find out which line it is and post it.