Jump to content

mysql_num_rows boolean error?


ChrisMartino
 Share

Recommended Posts

Hello there,

 

I'm having a issue where when I run the following statement:

 

$Session = $Module['MySQL']->RowCount("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')") == 1 ? true:false;

 

I am proceeded by the following error:

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Backend\MySQL-Module.php on line 49

 

Yet when I do the following statement:

 

echo $Module['MySQL']->RowCount("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')")

 

It gives me the output of 2 (That's the correct table row count)?

 

Does anybody have any insight into why this could be happening thanks.

 

Link to comment
Share on other sites

Your query failed due to an error and returned a FALSE value.

 

You must ALWAYS test if your query worked or failed before blindly attempting to access the results of that query.

 

echoing (or logging) msyql_error() will tell you why the query failed.

 

I've tried multiple times but mysql_error doesn't even return any error:

 

mysql_query("SELECT * FROM xhost_accounts WHERE (account_username = '{$Module['MySQL']->Escape($AccountUsername)}' OR account_email = '{$Module['MySQL']->Escape($AccountUsername)}') AND account_password = MD5('{$AccountPassword}')") or die(mysql_error());

Link to comment
Share on other sites

Then it's likely that your code that produces the error is using a different variable name in the mysql_num_rows() function call than what is being returned by the mysql_query statement or you have some other logic error that is overwriting the variable.

 

You are posting a couple of lines of code out of context and are expecting someone to tell you what your whole program is actually doing.

Link to comment
Share on other sites

You can do debug using following steps

 

1. Echo your query and run in  phpmyadmin

2. If it's get 2 rows from the table then your query is perfect

3. check your RowCount function

4. Check mysql_query and mysql_num_rows functions generate the same output what $Module['MySQL']->RowCount gives you.

Link to comment
Share on other sites

I made up a class that emulates what your's appears to do and the code you posted works as expected.

 

Your error must be coming from somewhere else in your code or the variables being put into the query don't have the same values for the line of code that produces the error and the line with the echo and are somehow breaking the query. What are you using the $Session variable for later in the code?

Link to comment
Share on other sites

I made up a class that emulates what your's appears to do and the code you posted works as expected.

 

Your error must be coming from somewhere else in your code or the variables being put into the query don't have the same values for the line of code that produces the error and the line with the echo and are somehow breaking the query. What are you using the $Session variable for later in the code?

 

Ha! Yes it was exactly as you say. It wasn't actually even that function call that was causing the error. I was calling the query function immediately after the call of that function and there was a error in my MySQL syntax, thus causing the error I was experiencing.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.