未定义的数组键"quantity"出现在C:\xampp\htdocs\login\cart-item.php中
<p>我正在按照教程视频进行操作,但是数据库中没有输出表格。我按照视频中的每一步操作。我还尝试将数量初始化为变量,但仍然无法工作</p>
<pre class="brush:php;toolbar:false;"><?php
session_start();
$connect = mysqli_connect("localhost", "root", "", "login_sample_db");
if(isset($_POST['add_to_cart'])){
if(isset($_SESSION['cart'])){
$session_array_id = array_column($_SESSION['cart'], "id");
if(!in_array($_GET['id'], $session_array_id)){
$session_array = array(
'id' => $_GET['id'],
"name" => $_POST['name'],
"price" => $_POST['price'],
"quantity" => $_POST['quantity']
);
$_SESSION['cart'][] = $session_array;
}
}else{
$session_array = array(
'id' => $_GET['id'],
"name" => $_POST['name'],
"price" => $_POST['price'],
"quantity" => $_POST['quantity']
);
$_SESSION['cart'][] = $session_array;
}
}?>
<头>
<标题>产品标题>
<link rel="stylesheet" type="text/css" href="cart-item.css">
<风格>
</风格>
</头>
<正文>
<div class="container-fluid">
<div class="col-md-12">
<div class="col-md-6">
购物车数据
<div class="col-md-12">
<div class="col-md-4">
;
<div class="col-md-6">
<h2 class="text-center">已选择的商品</h2>
<?php
$total = 0;
$output = "";
$output .= "
<table class='table table-bordered table-striped'>
<tr>
<th>ID</th>
<th>商品名称</th>
<th>商品价格</th>
<th>商品数量</th>
<th>总价格</th>
<th>操作</th>
</tr>
";
if(!empty($_SESSION['cart'])){
foreach($_SESSION['cart'] as $key => $value){
$output .= "
<tr>
<td>".$value['id']."</td>
<td>".$value['name']."</td>
<td>".$value['price']."</td>
<td>".$value['quantity']."</td>
<td>$".number_format($value['price'] * $value['quantity'])."</td>
<td>
<a href='cart-item.php?action=remove&id=".$value['id']."'>
<button class='btn btn-danger btn-block'>移除</button>
</a>
</td>
</tr>
";
$total = $total + $value['quantity'] * $value['price'];
}$output .= "
<tr>
<td colspan='3'></td>
<td></b>总价格</b></td>
<td>".number_format($total, 2)."</td>
<td>
<a href='cart-item.php?action=clearall'>
<button class='btn btn-warning btn-block'>清空</button>
</a>
</td>
</tr>
";
}
echo $output;
?>
</div>
</div>
</div>
</div>
</body>
</html></pre>
<p>我多次检查了数量数组键并与视频进行比较,与视频中的相同。我还应该尝试什么其他的东西吗?数据库中的表格也没有包含数量</p>