Hi there, and thanks in advance for taking a look at this problem. I have a form which I want to submit a variable to a session array. The form action targets a file called addToCart.php (this is for a shopping cart, woo) which contains this code:
<?php
session_start();
$prod = $_POST['pid'];
if(!isset($_SESSION['cart'])) {
$_SESSION['cart']=array();
}
if (isset($_SESSION['cart'][$prod])) {
$_SESSION['cart'][$prod]++;
}
else {
$_SESSION['cart'][$prod] = 1;
}
header("Location:".$_SERVER['HTTP_REFERER']);
?>
Originally the variable was sent to this file as part of a URL in an href attribute, using $prod = $_GET['pid']; so I thought it would simply be a matter of changing it to POST, being the metod of the form calling the file and pid being the name of the input tag in it..
Anyway, when I try this I receive
Fatal error: Cannot increment/decrement overloaded objects nor string offsets in addToCart.php on line 11
And I don't understand this, since I expected the variable $prod to be exactally the same.
Actually I'm not sure the original way worked either, but I don't have the file to check now. Anyway, thanks for your time 🙂