简体   繁体   中英

MySQLi INSERT Syntax Error

I get this error in my PHP script:

Notice: 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, 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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