开发者

How do I get my PHP update function to work? [duplicate]

This question already has an answer here: Syntax error due to using a reserved word as a table or column name in MySQL (1 answer) Closed 8 years ago.

See something wrong in my code? I can't get the update function to work.. weird thing is the rest works correctly, and the same code works 100% on another page.

<?php
include("config.php");

$id = $_GET['id'];

$number = $_GET['no'];

$result = mysql_query("SELECT * FROM comments WHERE commentid = '$id'")
or die(mysql_error());  

$row = mysql_fetch_array( $result );

mysql_query("update `comments` set like = like +1 where commentid = '$id'"); <--- only this here doesnt work
?>

And there is 1 line of html after that, a span tag getting some information out of the co开发者_运维问答mments table. My 'like' column is set to int(11), so I don't see that being the problem.

Hope this isnt another innatention mistake :/

Thanks alot to anyone who can help me out!

This is the error

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 = like +1 where commentid = '61'' at line 1


As EboMike posted, LIKE is a reserved keyword in MySQL.

You can either rename your column to something else that is not a keyword (preferred), or you can put a backtick (a backwards single quote) around it to tell MySQL it's a literal name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜