简体   繁体   English

MySQLi INSERT语法错误

[英]MySQLi INSERT Syntax Error

I get this error in my PHP script: 我在我的PHP脚本中收到此错误:

Notice: You have an error in your SQL syntax; 注意:您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like, dislike) VALUES (?, ?, ?, ?)' at line 1[`NSERT INTO workouts_likes_by_user (id_from_wall, user_name, like, dislike) VALUES (?, ?, ?, ?)] in /hermes/bosoraweb110/b720/ipg.workoutlogappcom/android_connect/update_likes.php5 on line 50 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以便在第1行['NSERT INTO trainings_likes_by_user(id_from_wall,user_name,like,dislike)附近使用'like,dislike)VALUES(?,?,?,?)'第50行的/hermes/bosoraweb110/b720/ipg.workoutlogappcom/android_connect/update_likes.php5中的VALUES(?,?,?,?)]

This is my query: 这是我的查询:

$sql = "INSERT INTO workouts_likes_by_user (id_from_wall, user_name, like, 
dislike) VALUES (?, ?, ?, ?)";

Thanks. 谢谢。

LIKE is a reserved keyword . LIKE保留关键字 If you want to use it in your query, wrap them in backticks like so: 如果要在查询中使用它,请将其包装在反引号中,如下所示:

$sql = "INSERT INTO workouts_likes_by_user 
(id_from_wall, user_name, `like`, dislike) 
VALUES (?, ?, ?, ?)";

Of course, not using reserved keywords in your query is the best way, but escaping them using backticks works, too. 当然,最好不要在查询中使用保留的关键字,但也可以使用反引号将其转义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM