添加到购物车功能错误[重复]

I create add to cart by watching tutorials and its shows error Warning:

mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\MyShop\functions\functions.php on line 44.

My Code is as follows:

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>";


    }
  }
}
</div>

Check whether you have assigned the values to $db

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