运行 php 时收到错误消息
然而结果出来了
这是我的代码
function cart() {
foreach($_SESSION as $name => $value) {
if ($value>0) {
if (substr($name, 0, 5) == 'cart_'){
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id=' .mysql_real_escape_string((int)$id));
while ($get_row = mysql_fetch_assoc($get)){
$sub = $get_row['price'] * $value;
echo $get_row['name'].' x '.$value.' @ £'.number_format($get_row['price'], 2).' = £'.number_format($sub, 2).' <a href="cart.php?remove='.$id.'">[-]</a> <a href="cart.php?add='.$id.'">[+]</a> <a href="cart.php?delete='.$id.'">[Delete]</a><br />' ;
}
}
$total += $sub;
}
}
echo $total;
}
?>
我收到一条错误消息
Notice: Undefined variable: total in C:\xampp\htdocs\shoppingcart\cart.php on line 54
第 54 行是
echo $total;
我的代码有什么问题??
我想我已经定义了代码
$total += $sub;
谢谢你帮助我:)