phpmysqlmysql-num-rows

MySQL Numrows Expecting Parameter


So I'm Getting The Error:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\All Connected\profile.php on line 117

While Try To Check For Friend Request Status Information, I Have Seen People Fix This Using A MySQL Error Dump Or Something Similar But I'm Not Sure, Can I Get Some Help?

This Is A Snippet Of My Code, Only The Parts That Need Fixing

    mysql_connect("illuzionz-pc", "-----", "----------");
    mysql_select_db("allcon");

    $my_id = $_SESSION['user_id'];
    $profile_id = $_GET['id'];

    $check_friend_query = mysql_query("SELECT id FROM friends WHERE (user_one='$my_id' AND user_two='$profile_id') OR (user_one='$profile_id' AND user_two='$my_id')");

    if(mysql_num_rows($check_friend_query) == 1){
      echo "<br><a class='pure-button pure-button-disabled' href='#'>Already Friends!</a><br>";
      echo "<a class='button-error pure-button' href='#'>Unfriend {$user['first_name']}</a>";
    } else {
      mysql_connect("illuzionz-pc", "Admin", "0A562B0CA0");
      mysql_select_db("allcon");

      $my_id = $_SESSION['user_id'];
      $profile_id = $_GET['id'];

      $from_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$profile_id' AND `to`='$my_id'");
      $to_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$my_id' AND `to='$profile_id'");

      if(mysql_num_rows($from_query) == 1){
        echo "<a class='button-secondary pure-button' href='#'>Ignore Friend Request</a><br>";
        echo "<a class='button-success pure-button' href='#'>Accept Friend Request</a>";
      } else if(mysql_num_rows($to_query) == 1){
        echo "<a class='button-error pure-button' href='#'>Cancel Friend Request</a>";
      } else {
        echo "<a class='pure-button pure-button-primary' href='#'>Send Friend Request</a>"; 
      }
}

Solution

  • Your mysql_query has returned false as you passed it invalid SQL. Fix your $to_query to:

    $to_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$my_id' AND `to`='$profile_id'");