我只是 php 的新手,我试图创建一个简单的购物车..但是每次我运行代码时,都会发生错误。它说“注意:未定义的变量:第 372 行 C:\wamp\www\irm\cart.php 中的总数”。这是我的代码:
function cart(){
echo "<table table border='1' cellpadding='10'>";
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 prod_id, prod_name, prod_price FROM products WHERE prod_id='.mysql_real_escape_string((int)$id));
while ($get_row = mysql_fetch_assoc($get)){
$sub = $get_row['prod_price']*$value;
echo "<tr><th>Product Name</th> <th>Quantity</th> <th>Price</th> <th>Total</th> <th>Increase</th> <th>Decrease</th> <th>Remove</th></tr>";
echo '<td>'.$get_row['prod_name'].'</td>';
echo '<td>'.$value.'</td>';
echo '<td>'.' PhP'.number_format($get_row['prod_price'], 2).'</td>';
echo '<td>'.' PhP'.number_format($sub, 2).'</td>';
echo '<td>'.'<a href="cart.php?remove='.$id.'">[-]</a>'.'</td>';
echo '<td>'.'<a href="cart.php?add='.$id.'">[+]</a>'.'</td>';
echo '<td>'.'<a href="cart.php?delete='.$id.'">[Delete]</a></td>';
}
}
$total += $sub;
}
}
if($total==0){
echo "Your cart is empty.";
}
else{
echo 'Total: PhP'.number_format($total, 2);
}