我找不出为什么我收到错误。按下添加按钮后,通知在刷新时消失。注意:即使在使用ISSET时未定义索引
<?php
session_start();
//session_destroy();
$page ='index.php';
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('cart') or die(mysql_error());
if (isset($_GET['add'])) {
$_SESSION['cart_'.$_GET['add']] +'1';
}
function products() {
$get = mysql_query('Select id, name, description, price from products where quantity > 0 order by id desc');
if (mysql_num_rows($get) == 0)
{
echo "There are no products to display";
}
while ($get_row = mysql_fetch_assoc($get)) {
echo '<p>'.$get_row['name'].'<br/>'
.$get_row['description'].'<br/>'
.number_format($get_row['price'],2)
.' <a href="cart.php?add='.$get_row['id'].'">
Add
</a>
</p>';
}
}
echo $_SESSION['cart_1']
?>
--------和的index.php
<?php require 'cart.php' ?>
<html>
<head>
</head>
<body>
<?php products(); ?>
</body>
</html>
首次执行的index.php后,收到错误: 注意:未定义指数:cart_1于E :\ xamp \ htdocs \ ShopCart \ cart.php on line 35
您可能忘记了该行中的'='符号... – bwoebi
由于'cart_123'条目之前未定义,它仍然会与'+ ='产生相同的通知。 – mario