I am stuck at php/mysql error which I am not able to trace. My table user_like structure is with sample data
id user_id song_id like
1 1 1 1
2 1 2 0
0 represents dislike and 1 represents like. Now I have query the table using php like http://myhost.net/server/services/songlike.php?uid=1&song_id=1 and I have also got result of like in my query using following code snippet.
$query="select * from atr_like where user_id='$uid' and song_id='$songid' limit 1 ";
$rs = mysql_query($query);
$row = mysql_fetch_assoc($rs);
print_r($row);
echo "<br>";
$like=$row['like'];
echo $like;
I am getting this value successfully. What I am doing is that if like is not present means null then inserting like in table. Else I am just toggeling its value by update means if it is zero then one and vice versa. Here I am getting error. My PHP Code is
if(mysql_num_rows($rs) > 0 && $like!=null)
{
if($like==1)
{
// "user has liked it already so dislike it update like to 0 ";
$query1="update atr_like set like=0 where user_id='$uid' and song_id='$songid'";
}
else
{
//"user has disliked it previously already so update like to 1 ";
$query1="update atr_like set like=1 where user_id='$uid' and song_id='$songid'";
}
}
else
{
echo "first time so insert record . user is going to like";
$query1="insert into atr_like (user_id,song_id,like) values ('$uid','$songid',1)";
}
$rs1 = mysql_query($query1)or die(mysql_error());
mysql_close($conn);
The error message is:
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=1 where user_id='1' and song_id='1375'' at line 1.
Is it due to a mysql problem that you can not update any records which is present in sql selection of previous query? Syntax looks fine but still showing syntax error.