Reputation: 45
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
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
Reputation: 140210
LIKE
is a keyword in SQL, use ´
SELECT userIP FROM `like` WHERE postID='$id' AND userIP='$ip
Upvotes: 1
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