我不知道为什么我会收到错误。按下添加按钮后,通知会在刷新时消失。
<?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 后,收到错误:Notice: Undefined index: cart_1 in E:\xamp\htdocs\ShopCart\cart.php on line 35