doutui6241 2019-07-19 21:37
浏览 86

在购物车会话中查看购物车商品错误在布尔值上调用成员函数fetch_assoc()

I have some basic shopping cart code to display all items in my carts session, the view_cart.php is displaying the error:

Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in C:\wamp64\www\shopping_cart\shopping_cart\view_cart.php on line 72

I have only edited the index a little the code was working perfectly before, now I just can't seem to get rid of this error..?

this is line 72: I cant see the error: ..

<?php
//initialize total
$total = 0;
if (!empty($_SESSION['cart'])){    
    //connection
    $conn = new mysqli('localhost', 'root', '', 'database');
    //create array of initail qty which is 1
    $index = 0;
    if (!isset($_SESSION['qty_array'])) {
        $_SESSION['qty_array'] = array_fill(0, count($_SESSION['cart']), 1);
    }
    $sql = "SELECT * FROM products WHERE id IN (" . implode(',', $_SESSION['cart']) . ")";
    $query = $conn->query($sql);
    while ($row = $query->fetch_assoc()){
    ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?