未定义的数组键"quantity"出现在C:\xampp\htdocs\login\cart-item.php中
P粉549412038
P粉549412038 2023-09-05 20:18:59
0
1
434
<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>
1
0
0
P粉549412038
P粉549412038

全部回复(1)
热门专题
更多>
热门文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!