php adding value to session
Posted
by
antikbd
on Stack Overflow
See other posts from Stack Overflow
or by antikbd
Published on 2012-10-10T09:18:46Z
Indexed on
2012/10/10
9:37 UTC
Read the original article
Hit count: 233
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']++;
}
}
© Stack Overflow or respective owner