如何解决我的php购物车页面中列出的错误
警告:为
中的foreach()提供的参数无效未定义变量:
中的wasFound注意:未定义的变量:
中的wap警告:array_push()要求参数1为数组,在
中给出null
页:
<?php
session_start(); // Start
include "storescripts/connect_to_mysql.php";
session_start(); // Start
if (isset($_POST['pid'])) {
$pid = $_POST['pid'];
if (isset($_POST['quanity'])) {
$wap = $_POST['quanity'];
}
$wasFound = 'false';
$i = '0';
// If the cart session variable is not set or cart array is empty
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
// RUN IF THE CART IS EMPTY OR NOT SET
$_SESSION["cart_array"] = array(0 => array("item_id" => $pid, "quantity" => $wap));
} else {
// RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
foreach ($_SESSION["cart_array"] as $each_item) {
$i++;
while (list($key, $value) = each($each_item)) {
if ($key == "item_id" && $value == $pid) {
// That item is in cart already so let's adjust its quantity using array_splice()
array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1)));
$wasFound = true;
} // close if condition
} // close while loop
} // close while loop
if ($wasFound == false) {
array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => $wap));
}
}
header("location: cart.php");
exit();
}
?>
感谢影响力