'Kuantiti' kunci tatasusunan yang tidak ditentukan muncul dalam C:\xampp\htdocs\login\cart-item.php
<p>Saya mengikuti video tutorial tetapi tiada jadual output dalam pangkalan data. Saya mengikuti setiap langkah dalam video.我还尝试将数量初始化为变量,但仍然无法工作</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 = tatasusunan(
'id' => $_GET['id'],
"nama" => $_POST['nama'],
"harga" => $_POST['harga'],
"kuantiti" => $_POST['kuantiti']
);
$_SESSION['cart'][] = $session_array;
}
}lain{
$session_array = tatasusunan(
'id' => $_GET['id'],
"nama" => $_POST['nama'],
"harga" => $_POST['harga'],
"kuantiti" => $_POST['kuantiti']
);
$_SESSION['cart'][] = $session_array;
}
}?>
<!DOCTYPE html>
<html>
<kepala>
<title>Produk</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="cart-item.css">
<gaya>
</style>
</head>
<badan>
<div class="bendalir-bekas">
<div class="col-md-12">
<div class="row">
<div class="col-md-6">
<h2 class="text-center">购物车数据</h2>
<div class="col-md-12">
<div class="row">
<?php
$query = "PILIH * DARI cart_item";
$result = mysqli_query($connect, $query);
while($row = mysqli_fetch_array($result)){
?>
<div class="col-md-4">
<form method="post" action="cart-item.php?id=<?= $row['id'] ?>">
<h5 class="text-center"><?= $row['name']; ?></h5>
<h5 class="text-center">$<?= number_format($row['price'], 2); ?></h5>
<input type="hidden" name="name" value="<?= $row['name'] ?>">
<input type="hidden" name="price" value="<?= $row['price'] ?>">
<input type="number" name="quantity" value="1" class="form-control">
<input type="submit" name="add_to_cart" class="btn btn-warning btn-block my-2" value="添加到购物车">
</form>
</div>
<?php
}
?>
</div>
</div>
</div>
<div class="col-md-6">
<h2 class="text-center">Item terpilih</h2>
<?php
$jumlah = 0;
$output = "";
$output .="
<table class='jalur meja bersempadan meja'>
<tr>
<th>ID</th>
<th>Nama Produk</th>
<th>Harga produk</th>
<th>Kuantiti item</th>
<th>Jumlah Harga</th>
<th>Operasi</th>
</tr>
";
if(!kosong($_SESSION['cart'])){
foreach($_SESSION['cart'] sebagai $key => $value){
$output .="
<tr>
<td>".$value['id']."</td>
<td>".$value['name']."</td>
<td>".$value['price']."</td>
<td>".$value['kuantiti']."</td>
<td>$".number_format($value['price'] * $value['kuantiti'])."</td>
<td>
<a href='cart-item.php?action=remove&id=".$value['id']."'>
<button class='btn btn-bahaya btn-block'>Alih keluar</button>
</a>
</td>
</tr>
";
$total = $total + $value['kuantiti'] * $value['price'];
}$output .="
<tr>
<td colspan='3'></td>
<td></b>Jumlah Harga</b></td>
<td>".number_format($total, 2).."</td>
<td>
<a href='cart-item.php?action=clearall'>
<button class='btn btn-warning btn-block'>Kosongkan</button>
</a>
</td>
</tr>
";
}
echo $output;
?>
</div>
</div>
</div>
</div>
</badan>
</html></pre>
<p>Saya menyemak kunci tatasusunan kuantiti beberapa kali dan membandingkan dengan video, sama seperti dalam video. Adakah terdapat apa-apa lagi yang perlu saya cuba? Jadual dalam pangkalan data juga tidak mengandungi kuantiti</p>