user1405674
user1405674

Reputation: 45

Warning mysql_num_rows(): supplied argument is not a valid MySQL result

Why i have this error and how to fix this, I've double checked everything and all is okay

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/sharinga/public_html/ccccc.com/app/like/like.php on line 15
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 'like WHERE postID='81' AND userIP='2x2.2x0.x5.xxx'' at line 1

Here is sql

$ip_sql = mysql_query("SELECT userIP FROM like WHERE postID='$id' AND userIP='$ip'");
$count = mysql_num_rows($ip_sql) or die(mysql_error());
if($count==0)
{...

Upvotes: 0

Views: 123

Answers (3)

er_jack
er_jack

Reputation: 112

Try connecting first. Are you looking for the null case? If so you have to search a certain row not $count as a whole.

$conn = mysql_connect("localhost", "user", "pass");
$ip_sql = mysql_query("SELECT userIP FROM like WHERE postID='$id' AND userIP='$ip'",$conn);
$count = mysql_num_rows($ip_sql) or die(mysql_error());
if ($count['postID'}==""){
}

Upvotes: 0

Esailija
Esailija

Reputation: 140210

LIKE is a keyword in SQL, use ´

SELECT userIP FROM `like` WHERE postID='$id' AND userIP='$ip

Upvotes: 1

Zoltan Toth
Zoltan Toth

Reputation: 47667

LIKE is a reserved word - escape it

$ip_sql = mysql_query("SELECT userIP FROM `like` WHERE postID='$id' AND userIP='$ip'");

Upvotes: 4

Related Questions