This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result
                                
                                    (32个答案)
                                
                        
                                2年前关闭。
            
                    
我通过观看教程来创建添加到购物车,它显示错误警告:


  mysqli_num_rows()期望参数1为mysqli_result,布尔
  在第44行的C:\ xampp \ htdocs \ MyShop \ functions \ functions.php中给出。


我的代码如下:

function cart(){

  if(isset($_GET['add_cart'])){

    global $db;

    $ip = getIpofCostumer();

    $pro_id = $_GET['add_cart'];

    $check_pro = "select * from cart where ip_add='$ip' AND p_id='$pro_id'";

    $run_check = mysqli_query($db, $check_pro);

    if (mysqli_num_rows($run_check)>0){

        echo "";

        } else {

            $insert_pro = "insert into cart (p_id,ip_add) values ('$pro_id','$ip')";

            $run_pro = mysqli_query($db, $insert_pro);

            echo "<script>Window.open('cart.php','_self')</script>";


    }
  }
}

最佳答案

检查是否已将值分配给$db

 $run_check = mysqli_query($db, $check_pro);

关于php - 添加到购物车功能错误[重复项],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42107659/

10-16 07:41