Jump to content

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'

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.