如何让我的 PHP 更新功能发挥作用?
看到我的代码有问题吗?我无法让更新功能工作..奇怪的是其余部分工作正常,并且相同的代码在另一个页面上 100% 工作。
<?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
?>
之后有 1 行 html,一个 span 标签从注释表中获取一些信息。 我的“喜欢”列设置为 int(11),所以我不认为这是问题所在。
希望这不是另一个无意的错误:/
非常感谢任何可以帮助我的人!
这是错误
您的 SQL 语法有错误; 检查对应的手册 您的 MySQL 服务器版本 在 'like = like 附近使用正确的语法 +1,其中 commentid = '61'' 在第 1 行
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 comments 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如 EboMike 所发布的,LIKE 是 MySQL 中的保留关键字。
您可以将列重命名为非关键字(首选)的其他名称,也可以在其周围添加反引号(向后的单引号)以告诉 MySQL 这是一个字面名称。
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.