Exoon Posted January 11, 2009 Share Posted January 11, 2009 Hello, Im getting an error when using this bit of code, Ive looked on php.net but can't see to find an anwser. $sql = "SELECT * FROM links"; $result = mysql_query($sql) or die(mysql_error()); $num_rows = mysql_num_rows($result); The error im getting is: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Link to comment https://forums.phpfreaks.com/topic/140376-solved-mysql_num_rows-error/ Share on other sites More sharing options...
dclamp Posted January 11, 2009 Share Posted January 11, 2009 there is something wrong with your query, not the php. try "SELECT * FROM `links` WHERE 1" Link to comment https://forums.phpfreaks.com/topic/140376-solved-mysql_num_rows-error/#findComment-734598 Share on other sites More sharing options...
Exoon Posted January 11, 2009 Author Share Posted January 11, 2009 i swaped it over to what you said. $sql = "SELECT * FROM `links` WHERE 1" $result = mysql_query($sql) or die(mysql_error()); $num_rows = mysql_num_rows($result); and i now get the following error Parse error: syntax error, unexpected T_VARIABLE in update_link_hits.php on line 6 Line 6 is the $result = mysql line Link to comment https://forums.phpfreaks.com/topic/140376-solved-mysql_num_rows-error/#findComment-734600 Share on other sites More sharing options...
trq Posted January 11, 2009 Share Posted January 11, 2009 Your now missing a ; from line 5. Link to comment https://forums.phpfreaks.com/topic/140376-solved-mysql_num_rows-error/#findComment-734601 Share on other sites More sharing options...
trq Posted January 11, 2009 Share Posted January 11, 2009 Just as an example, the query process should always be wrapped within if statements so as to catch any errors. eg; $sql = "SELECT * FROM `links` WHERE 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // its now safe to display any data. } else { // no results found. } } else { // your query failed. } Link to comment https://forums.phpfreaks.com/topic/140376-solved-mysql_num_rows-error/#findComment-734603 Share on other sites More sharing options...
Exoon Posted January 11, 2009 Author Share Posted January 11, 2009 Thanks, Its working now and thanks for the tip ill remember to do it from that now. Link to comment https://forums.phpfreaks.com/topic/140376-solved-mysql_num_rows-error/#findComment-734604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.