致命的错误未接收到null in in in in in in in的会员函数fetch_assoc()的错误调用



参考图像我只是不知道自己错的地方。有人可以帮我吗?我现在感到很愚蠢

 function total_price() {
        $total = 0;
        global $con;
        $ip = getIp();
        $select_price = $con->query("SELECT * from shoppingcart WHERE IP_address='$ip'");
        while($row = $select_price->fetch_assoc()) {
            $pro_id = $row['Product_id'];
            $quan = $row['Quantity'];
            $query = $con->query("SELECT * FROM products WHERE prod_id='$pro_id'");
            while($row2 = $query->fetch_assoc()) {
                $row2['product_price'] *= $quan;
                $productprice = array($row2['product_price']);
                $values = array_sum($productprice);
                $total += $values;
            }
        }
        echo "₱: ".$total;
    }

我认为您的$ con-> query(...(失败,因此您的 $select_priceFALSE,而不是具有某些成员函数的对象。

查看$ mysqli ::查询的文档

http://php.net/manual/en/mysqli.query.php

如果要获得SQL错误打印$con->error的结果。

例如:

     $select_price = $con->query("SELECT * from shoppingcart WHERE IP_address='$ip'");
    if($select_price == FALSE) {
        echo "SQL-Error:".$con->error
        exit;
    }
            while($row = $select_price->fetch_assoc()) {
...

如果fetch_assoc失败,结果集有问题。

问题:

$ query

$ select_price

不是有效的结果集。

原因可能是数据库的查询失败。

您可以通过:

检查一下

print_r($ select_price(;print_r($ query(;

应该输出:ressource id #xx->如果没有,请再次查看查询再次直接SQL。

希望这有帮助

最新更新