エラーが発生する理由がわかりません。[追加] ボタンを押した後、通知は更新時に消えます。
<?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