我被困在php/mysql错误,我无法跟踪。 我的表user_like结构与样本数据错误在同时选择和更新在mysql
id user_id song_id like
1 1 1 1
2 1 2 0
0表示厌恶和1表示等。 现在我查询表使用PHP像 http://myhost.net/server/services/songlike.php?uid=1&song_id=1 和我也得到了使用下面的代码片段中的结果。
$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;
我正在成功获取此值。 我正在做的是,如果像不存在意味着null然后插入像表中。 否则我只是用更新的方式来表示它的价值,如果它是零则一,反之亦然。 在这里,我收到错误。 我的PHP代码是
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);
错误消息:
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.
它是由于MySQL的问题,你不能更新任何记录,这是目前在先前的查询的SQL选择? 语法看起来不错,但仍然显示语法错误。
请避免使用单 – 2013-02-22 06:30:20
你正在使用MySQL保留名称作为列名,请表前缀名atr_like.like = 1 – Saqueib 2013-02-22 06:31:41
真的感谢花费宝贵的时间。你让你的工作变得简单。 – 2013-02-22 07:24:45