webmaster1 Posted November 26, 2008 Share Posted November 26, 2008 Hi All, Can anybody spot whats discrepant with the below query? It works fine without the WHERE index = '134' part. It seems to be related to the number of rows. Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource <?php mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM test WHERE index = '134' ORDER BY date"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> Link to comment https://forums.phpfreaks.com/topic/134402-solved-basic-mysql-query-error-mysql_numrows/ Share on other sites More sharing options...
Michdd Posted November 26, 2008 Share Posted November 26, 2008 It's mysql_num_rows not mysql_numrows Link to comment https://forums.phpfreaks.com/topic/134402-solved-basic-mysql-query-error-mysql_numrows/#findComment-699701 Share on other sites More sharing options...
webmaster1 Posted November 26, 2008 Author Share Posted November 26, 2008 It's mysql_num_rows not mysql_numrows Fixed but exact same error. Perhaps its the query itself? Link to comment https://forums.phpfreaks.com/topic/134402-solved-basic-mysql-query-error-mysql_numrows/#findComment-699704 Share on other sites More sharing options...
PFMaBiSmAd Posted November 26, 2008 Share Posted November 26, 2008 It's either mysql_num_rows (current name) or mysql_numrows (old depreciated name.) Both work and an incorrect function name would not cause the error being output. index is a reserved mysql keyword. Change your column name to something else or enclose it in back-ticks. Link to comment https://forums.phpfreaks.com/topic/134402-solved-basic-mysql-query-error-mysql_numrows/#findComment-699709 Share on other sites More sharing options...
revraz Posted November 26, 2008 Share Posted November 26, 2008 Using mysql_error() after your query would show you the reason. Link to comment https://forums.phpfreaks.com/topic/134402-solved-basic-mysql-query-error-mysql_numrows/#findComment-699711 Share on other sites More sharing options...
webmaster1 Posted November 26, 2008 Author Share Posted November 26, 2008 I've changed my primary key name from index to [index] in mySQL and my code. I still recieve the same error: <?php mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM test WHERE [index] = '134' ORDER BY date"; mysql_error(); $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); ?> revraz: Was mysql_error() meant to have a semi-colon? If yes, I recieve the exact same error as above. If no, I recieve a parse error. Link to comment https://forums.phpfreaks.com/topic/134402-solved-basic-mysql-query-error-mysql_numrows/#findComment-699715 Share on other sites More sharing options...
revraz Posted November 26, 2008 Share Posted November 26, 2008 Not [index], `index`, or better yet, just change the name. $result=mysql_query($query) or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/134402-solved-basic-mysql-query-error-mysql_numrows/#findComment-699717 Share on other sites More sharing options...
webmaster1 Posted November 26, 2008 Author Share Posted November 26, 2008 Changed index to urn. $query="SELECT * FROM test WHERE urn = '134' ORDER BY date"; Works perfectly! Link to comment https://forums.phpfreaks.com/topic/134402-solved-basic-mysql-query-error-mysql_numrows/#findComment-699725 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.