RCT3Xtreme Posted July 6, 2007 Share Posted July 6, 2007 Hi, I'm sure you get this one all the time, but whatever... I'm getting the error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in... etc, and have no idea why. Here is the problematic code: <?php // [...] some code missing [...] if (empty($errors)) { // If all is good so far. $checknamedata = "SELECT * FROM pages WHERE page_name= '$pagename';"; $checknamedatar = @mysql_query($checknamedata); if (mysql_num_rows($checknamedatar) == 0) { // <-- this is the problem line, but it is something to do with the query I think. ?> I'll be thankful for any help. Quote Link to comment https://forums.phpfreaks.com/topic/58774-solved-mysql-num-rows-error/ Share on other sites More sharing options...
AndyB Posted July 6, 2007 Share Posted July 6, 2007 $checknamedata = "SELECT * FROM pages WHERE page_name= '$pagename';"; should be $checknamedata = "SELECT * FROM pages WHERE page_name= '$pagename'"; For reference, it's a good idea to use rational error trapping while testing. For example: $checknamedatar = mysql_query($checknamedata) or die("Error: ". mysql_error(). " with query ". $checknamedata); // show useful error info Quote Link to comment https://forums.phpfreaks.com/topic/58774-solved-mysql-num-rows-error/#findComment-291581 Share on other sites More sharing options...
RCT3Xtreme Posted July 6, 2007 Author Share Posted July 6, 2007 In reply to the ";" thing, I took it out and nothing changed. Surely it wouldn't matter anyway, ; is the delimiter for MySQL and isn't required for queries.. (well, I thought that ) Quote Link to comment https://forums.phpfreaks.com/topic/58774-solved-mysql-num-rows-error/#findComment-291592 Share on other sites More sharing options...
AndyB Posted July 7, 2007 Share Posted July 7, 2007 and what happened when you used the error trapping I suggested? Quote Link to comment https://forums.phpfreaks.com/topic/58774-solved-mysql-num-rows-error/#findComment-291836 Share on other sites More sharing options...
RCT3Xtreme Posted July 7, 2007 Author Share Posted July 7, 2007 I put that in too. (actually, I had error trapping in but took it out for simplicity in showing code) The error(s) generated are: Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/fhlinux171/c/creative.design-uk.biz/user/htdocs/test/admin/addpage.php on line 34 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/fhlinux171/c/creative.design-uk.biz/user/htdocs/test/admin/addpage.php on line 34 Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) with query SELECT * FROM pages WHERE page_name= 'gd' Quote Link to comment https://forums.phpfreaks.com/topic/58774-solved-mysql-num-rows-error/#findComment-291846 Share on other sites More sharing options...
RCT3Xtreme Posted July 7, 2007 Author Share Posted July 7, 2007 Ah, I fixed the errors! I overlooked the fact that I didn't select a DB.. Quote Link to comment https://forums.phpfreaks.com/topic/58774-solved-mysql-num-rows-error/#findComment-291849 Share on other sites More sharing options...
AndyB Posted July 7, 2007 Share Posted July 7, 2007 Good error trapping often helps Quote Link to comment https://forums.phpfreaks.com/topic/58774-solved-mysql-num-rows-error/#findComment-291850 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.