为什么会出现这种情况
<?php require '../tools.func.php'; require '../db.func.php'; require 'auth.php'; //1.从数据表中查询购物车的数据 $uid=getSession('id','shop'); $prefix=getDBPrefix(); $sql="SELECT id,price,products,quantity FROM {$prefix}cart WHERE uid='$uid'"; $cart_page_data=queryOne($sql); $cart_page_data['products']=json_decode($cart_page_data['products'],true); //遍历查询结果 require 'header.php'; ?> <div class="cart-main-area bg__white"> <div class="container"> <div class="row"> <div class="col-md-12 col-sm-12 col-xs-12"> <?php if(hasInfo()) echo getInfo();?> <form action="#"> <div class="table-content table-responsive"> <table> <thead> <tr> <th class="product-thumbnail"></th> <th class="product-name">商品名称</th> <th class="product-price">单价</th> <th class="product-quantity">数量</th> <th class="product-subtotal">总计</th> <th class="product-remove">编辑</th> </tr> </thead> <tbody> <?php if(!empty($cart_page_data)):?> <?php foreach($cart_page_data['products'] as $pid=> $cart_product):?> <tr> <td class="product-thumbnail"> <a href="product_details.php?id=<?php echo $pid;?>"> <img src="assets/uploads/default.jpeg" alt="product img" /> </a> </td> <td class="product-name"> <a href="product_details.php?id=<?php echo $pid;?>"><?php echo $cart_product['product']['name']; ?></a> </td> <td class="product-price"><span class="amount">¥<?php echo $cart_product['product']['price'];?></span></td> <td class="product-quantity"> <input type="number" disabled value="<?php echo $cart_product['quantity']; ?>" /> </td> <td class="product-subtotal"> ¥<?php echo $cart_product['product']['price']*$cart_product['quantity'];?> </td> <td class="product-remove"> <a href="=cart_del.php?product_id=<?php echo $pid;?>">X</a> </td> </tr> <?php endforeach;?> <?php endif;?> </tbody> </table> </div> <div class="row"> <div class="col-md-8 col-sm-7 col-xs-12"> <div class="buttons-cart"> <a href="index.php">继续购物</a> </div> </div> <div class="col-md-4 col-sm-5 col-xs-12"> <div class="cart_totals"> <table> <tbody> <tr class="cart-subtotal"> <th>小计</th> <td><span class="amount">¥<?php echo isset($cart_page_data['price'])?$cart_page_data['price']:'0.0';?></span></td> </tr> <tr class="shipping"> <th>快递</th> <td> <ul id="shipping_method"> <li> <input type="radio" checked /> <label> 包邮 </label> </li> <li></li> </ul> </td> </tr> <tr class="order-total"> <th>总价</th> <td> <strong><span class="amount">¥<?php echo isset($cart_page_data['price'])?$cart_page_data['price']:'0.0'; ?> </span></strong> </td> </tr> </tbody> </table> <div class="wc-proceed-to-checkout" style="clear: both;"> <a href="checkout.html">去付款</a> </div> </div> </div> </div> </form> </div> </div> </div> </div> <div class="only-banner ptb--10 bg__white"> </div> <?php require 'footer.php'; ?>
<?php require '../tools.func.php'; require '../db.func.php'; require 'auth.php'; $product_id=intval($_GET['product_id']); if(empty($product_id)){ header('location:cart.php'); exit; } //查询当前购物车 $prefix=getDBPrefix(); $uid=getSession('id','shop'); $sql="SELECT id,price,products,quantity FROM {$prefix}cart WHERE uid='$uid'"; $cart=queryOne($sql); // 2. 将购物车当中对应id的商品删除,更新总价格,总数量 $cart['products']=json_decode($cart['products'],true); $cart['price']-=$cart['products'][$product_id]['quantity']*$cart['products'][$product_id]['price']; $cart['quantity']-=$cart['products'][$product_id]['quantity']; unset($cart['products'][$product_id]); $cart['products']=addslashes(json_encode($cart['products'])); $sql="UPDATE {$prefix}cart SET price='{$cart['price']}', quantity='{$cart['quantity']}', products='{$cart['products']}' WHERE uid='$uid'"; if(execute($sql)){ setInfo('删除成功'); }else{ setInfo('删除失败'); } header('location:cart.php');
2
收起
正在回答 回答被采纳积分+1
3回答
PHP小白零基础入门
- 参与学习 人
- 提交作业 626 份
- 解答问题 4928 个
想要学好Web后端开发的中流砥柱语言,本阶段为你轻松铺就扎实的基础,从前端网页布局的搭建到后台PHP开发,助你从零基础到掌握主流开发语言。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星