3 Replies - 1375 Views - Last Post: 15 January 2012 - 06:15 PM Rate Topic: -----

#1 JohnPringle  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 36
  • Joined: 13-January 12

mysql_num_rows() expects resource not boolean?

Posted 15 January 2012 - 05:59 PM

Hello, I am getting an error when I try running this piece of code, can anyone tell my what I have done wrong...

$query = mysql_query("SELECT username FROM temp_users WHERE username='{$username}'");
        if(mysql_num_rows($query)==1){
            $register_errors[] = "That username has already been taken, please choose another";
        }



the error is this...

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\PringleSite_v1\register.php on line 78
(FYI - It's actually line 2 in this code snippet)

Thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: mysql_num_rows() expects resource not boolean?

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10366
  • View blog
  • Posts: 38,403
  • Joined: 27-December 08

Re: mysql_num_rows() expects resource not boolean?

Posted 15 January 2012 - 06:03 PM

You should check:
if(!$resultOfQuery){
    die("There was an error: " . mysql_error());
}

//or more simple
mysql_query($query) or die("There was an error" . mysql_error());



This error means that there was a problem with your query.
Was This Post Helpful? 0
  • +
  • -

#3 JohnPringle  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 36
  • Joined: 13-January 12

Re: mysql_num_rows() expects resource not boolean?

Posted 15 January 2012 - 06:05 PM

Don't worry, I figured it out:)

$query = "SELECT username FROM temp_users WHERE username='{$username}'";
        $result = mysql_query($query);
        if(mysql_num_rows($result)==1){
            $register_errors[] = "That username has already been taken, please choose another";
        }


Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6036
  • View blog
  • Posts: 23,418
  • Joined: 23-August 08

Re: mysql_num_rows() expects resource not boolean?

Posted 15 January 2012 - 06:15 PM

PROTIP: Scroll to the bottom of this page. Check out the Related PHP Topics. Next scroll back up to the top and check out the post titled "PHP - FAQ, Guides, Resources".

Posted Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1