将产品添加到购物篮

时间:2019-06-05 08:11:50

标签: php

我正在尝试在购物篮中添加产品,但是我无法正常工作。我收到警告

  

警告:mysqli_fetch_array()期望参数1为mysqli_result,在C:\ Program Files(x86)\ EasyPHP-Devserver-17 \ eds-www \ Esigelec Online Sales 2019 \ cart.php在线中给出的布尔值

我有一个名为cart的数据库。

<?php
    $ip = getIp();
    $total = 0;
    $sel_price = "select * from cart where ip_add = '$ip'";
    $run_price = mysqli_query($con,$sel_price);
    while($cart_row = mysqli_fetch_array($run_price)){
        $pro_id = $cart_row['p_id'];
        $pro_qty = $cart_row['qty'];
        $pro_price = "select * from products where pro_id = '$pro_id' and sflag = 0;";
        $run_pro_price = mysqli_query($con, $pro_price);
        while ($pro_row = mysqli_fetch_array($run_pro_price)){
            $pro_title = $pro_row['pro_title'];
            $pro_image = $pro_row['pro_image'];
            $pro_price = $pro_row['pro_price'];
            $pro_price_all_items = $pro_price * $pro_qty;
            $total += $pro_price_all_items;
            ?>
            <tr align="center">
                <td><input type="checkbox" name="remove[]"
                           value="<?php echo $pro_id; ?>"></td>
                <td><?php echo $pro_title; ?> <br>
                    <img src="admin/product_images/<?php echo $pro_image; ?>"
                         width="60" height="60">
                </td>
                <td><input size="2" name="qty[]" value="<?php echo $pro_qty;?>">
                    <input name="product_id[]" type="hidden" value="<?php echo $pro_id;?>">
                </td>
                <td><?php echo "$".$pro_price ; ?></td>
                <td><?php echo "$".$pro_price_all_items; ?></td>
            </tr>
            <?php
        }
    }
?>

此行会引起问题:while ($pro_row = mysqli_fetch_array($run_pro_price))

1 个答案:

答案 0 :(得分:0)

mysqli_query()在出现错误的情况下返回FALSE。 检查您的查询