twiggs462 Posted July 25, 2012 Share Posted July 25, 2012 A client of mine is having an issue with an admin area of their site that I never encountered before... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource The code that is being referenced is: // new sql to pull associated products for seleceted family $restwoway = mysql_query("SELECT * FROM members order by name;"); $numrows=mysql_num_rows(restwoway); if($numrows=0){ echo "Invalid entry"; } else { ?> Anyone see any errors here or... do you need me to provide additional details. I never seen this error before and not sure how to address it . Thank you for any ideas you might have. Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/ Share on other sites More sharing options...
Pikachu2000 Posted July 25, 2012 Share Posted July 25, 2012 The query is failing. Echoing mysql_error should give you some insight as to why. Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364332 Share on other sites More sharing options...
twiggs462 Posted July 25, 2012 Author Share Posted July 25, 2012 Ok. I just added this: $restwoway = mysql_query($sql); if (!$restwoway) { die("I JUST GOT A QUERY ERROR!!!<br />Query is: $sql<br />Error is: ".mysql_error()); } And it resulted in this: I JUST GOT A QUERY ERROR!!! Query is: Error is: Query was empty Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364335 Share on other sites More sharing options...
Jessica Posted July 25, 2012 Share Posted July 25, 2012 And.... Do you see a problem there? Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364336 Share on other sites More sharing options...
jazzman1 Posted July 25, 2012 Share Posted July 25, 2012 Php is not like C++. $numrows=mysql_num_rows(restwoway); Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364338 Share on other sites More sharing options...
twiggs462 Posted July 25, 2012 Author Share Posted July 25, 2012 changed this: $numrows=mysql_num_rows(restwoway); to this: $numrows=mysql_num_rows($restwoway); Seems to have fixed it... I feel... well... ridiculous... thanks for the help in steering me. Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364340 Share on other sites More sharing options...
Pikachu2000 Posted July 25, 2012 Share Posted July 25, 2012 Actually in this case, in your original code, look at the value you've passed to mysql_num_rows(). Is it missing something? Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364341 Share on other sites More sharing options...
Jessica Posted July 25, 2012 Share Posted July 25, 2012 Also, the if() statement will ALWAYS return true. Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364344 Share on other sites More sharing options...
twiggs462 Posted July 25, 2012 Author Share Posted July 25, 2012 Actually in this case, in your original code, look at the value you've passed to mysql_num_rows(). Is it missing something? Not sure... I will need to look further. Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364345 Share on other sites More sharing options...
twiggs462 Posted July 25, 2012 Author Share Posted July 25, 2012 Also, the if() statement will ALWAYS return true. Does this mean that this is somehow just generally incorrect? // new sql to pull associated products for seleceted family $restwoway = mysql_query("SELECT * FROM members order by name;"); $numrows=mysql_num_rows($restwoway); if($numrows=0){ echo "Invalid entry"; } else { ?> Sorry I am new to this and need to brush up... new more about PHP years back... had to learn ASP for work and now feel rusty Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364348 Share on other sites More sharing options...
Jessica Posted July 25, 2012 Share Posted July 25, 2012 In the if(), you're assigning, not comparing. So it will always evaluate to true. Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364349 Share on other sites More sharing options...
twiggs462 Posted July 25, 2012 Author Share Posted July 25, 2012 I don't remember how to compare or what it should be compared to... Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364350 Share on other sites More sharing options...
Pikachu2000 Posted July 25, 2012 Share Posted July 25, 2012 Actually in this case, in your original code, look at the value you've passed to mysql_num_rows(). Is it missing something? Not sure... I will need to look further. What are variables supposed to start with? I don't remember how to compare or what it should be compared to... Assignment operators Comparison operators Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364353 Share on other sites More sharing options...
Jessica Posted July 25, 2012 Share Posted July 25, 2012 http://php.net/docs.php Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364354 Share on other sites More sharing options...
jcbones Posted July 25, 2012 Share Posted July 25, 2012 = assign == compare === strict compare Quote Link to comment https://forums.phpfreaks.com/topic/266242-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1364382 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.