Notice: Undefined index: 9781400108503 in C:xampphtdocsibshelf.comcart.php on line 38
Notice: Undefined index: 9781400108503 in C:xampphtdocsibshelf.comcart.php on line 42
Warning: array_count_values(): Can only count STRING and INTEGER values! in C:xampphtdocsibshelf.comcart.php on line 53
// book_isbn got from form post method
if(isset($_POST['bookisbn'])){
$book_isbn = $_POST['bookisbn'];
}
if(isset($book_isbn))
{
// new item selected
if(!isset($_SESSION['cart']))
{
// $_SESSION['cart'] is associative array that bookisbn => qty
$_SESSION['cart'] = array();
$_SESSION['total_items'] = 0;
$_SESSION['total_price'] = '0.00';
}
if(!isset($_SESSION['cart'][$book_isbn]))
{
$_SESSION['cart'][$book_isbn] = 1;
} elseif(isset($_POST['cart']))
{
$_SESSION['cart'][$book_isbn]++;
unset($_POST);
}
}
// if save change button is clicked , change the qty of each bookisbn
if(isset($_POST['save_change'])){
foreach($_SESSION['cart'] as $isbn =>$qty){
if($_POST[$isbn] == '0')
{
unset($_SESSION['cart']["$isbn"]);
} else {
$_SESSION['cart']["$isbn"] = $_POST["$isbn"];
}
}
}
$title = "Your shopping cart";
if(isset($_SESSION['cart']) && (array_count_values($_SESSION['cart']))){
$_SESSION['total_price'] = total_price($_SESSION['cart']);
$_SESSION['total_items'] = total_items($_SESSION['cart']);
question from:
https://stackoverflow.com/questions/66058057/add-item-to-the-cart-and-change-quentity-show-following-error-how-to-fix-it 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…