Hello, I keep getting this error when I run the below query. Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource My code: mysql_connect($dbhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM $tablename WHERE loc='$ckey'"; $result=mysql_query($query); $num=mysql_numrows($result); What is happenning? Thank you
True but that would have caused an unknown function error. Seems like that missing _ might not be the only issue.
In that case, you may need to change ... $query="SELECT * FROM $tablename WHERE loc='$ckey'"; into $query="SELECT * FROM `$tablename` WHERE `loc`='$ckey'";
It would be this in my style: $query = "SELECT * FROM " . $tablename . " WHERE loc='" . $ckey . "'"; $result = mysql_query($query); $num = mysql_num_rows($result); PHP: All nicely spaced...
Shouldn't it be.. $query = "SELECT * FROM `" . $tablename . "` WHERE loc='" . $ckey . "'"; $result = mysql_query($query); $num = mysql_num_rows($result); PHP: Since what you said is exactly the same as is already being done, just looking prettier? xP JEET, can you tell us what $tablename is?
Hi, I tried all your methods but I am still getting the error. The code is : <? mysql_connect($dbhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM $tablename"; $result=mysql_query($query); $num=mysql_num_rows($result); echo $num; ?> See it at: http://www.ad4business.com/1/w/admin/showall.php It should at least echo 0 even if the db is empty... What to do?
I AM A BIG FAT IDIOT. The password I was using to connect to db was wrong. It's fine now. A million thanks to all you who looked in this.
I never bother with the comma's around the table name. So annoying because there's a `, ', " etc. So I got used to leaving them out entirely. JEET, it echoes the first $num, then it goes pearshape.... EDIT: see you got it...
"When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth." - Sherlock Holmes