如何让我的 PHP 更新功能发挥作用?

发布于 2024-09-27 08:33:24 字数 698 浏览 6 评论 0原文

看到我的代码有问题吗?我无法让更新功能工作..奇怪的是其余部分工作正常,并且相同的代码在另一个页面上 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋凉 2024-10-04 08:33:24

正如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文