ChrisMartino Posted September 27, 2010 Share Posted September 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214499-mysql_num_rows-boolean-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 27, 2010 Share Posted September 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214499-mysql_num_rows-boolean-error/#findComment-1116160 Share on other sites More sharing options...
ChrisMartino Posted September 27, 2010 Author Share Posted September 27, 2010 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()); Quote Link to comment https://forums.phpfreaks.com/topic/214499-mysql_num_rows-boolean-error/#findComment-1116173 Share on other sites More sharing options...
PFMaBiSmAd Posted September 27, 2010 Share Posted September 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214499-mysql_num_rows-boolean-error/#findComment-1116174 Share on other sites More sharing options...
chintansshah Posted September 27, 2010 Share Posted September 27, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214499-mysql_num_rows-boolean-error/#findComment-1116179 Share on other sites More sharing options...
PFMaBiSmAd Posted September 27, 2010 Share Posted September 27, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/214499-mysql_num_rows-boolean-error/#findComment-1116239 Share on other sites More sharing options...
ChrisMartino Posted September 28, 2010 Author Share Posted September 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/214499-mysql_num_rows-boolean-error/#findComment-1116806 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.