Jump to content

[SOLVED] MySQL Num Rows error.


RCT3Xtreme

Recommended Posts

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. :)

Link to comment
https://forums.phpfreaks.com/topic/58774-solved-mysql-num-rows-error/
Share on other sites

$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

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'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.