【发布时间】:2010-12-11 21:57:03
【问题描述】:
我正在尝试制作购物车并从网上获取代码..
<?php
session_start();
require_once 'class/Item.php';
$product_id = $_REQUEST['i_id'];
$action = $_REQUEST['action'];
$item= new Item();
if($product_id && !$item->productExists($product_id)) {
die("Error. Product Doesn't Exist");
}
switch($action) {
case "add":
$_SESSION['cart'][$product_id]++;
break;
case "remove":
$_SESSION['cart'][$product_id]--;
if($_SESSION['cart'][$product_id] == 0) unset($_SESSION['cart'][$product_id]);
break;
case "empty":
unset($_SESSION['cart']);
break;
}
?>
但在将第一项添加到购物车时出错。我该如何纠正它。
错误:
注意:未定义索引:第 16 行 C:\wamp\www\website\store_esp\addtocart.php 中的购物车
注意:未定义索引:第 16 行 C:\wamp\www\website\store_esp\addtocart.php 中的 2
【问题讨论】:
-
也许引用一个不存在的关联数组成员是错误的?
-
可能是
undefined index警告。我在想$_SESSION['cart'][$product_id]++;可能是问题所在。
标签: session session-variables session-state php