0

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.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
dasdasd
  • 1,971
  • 10
  • 45
  • 72
  • You have to insert something in the ? values before passing them to a query. – Vilsol Sep 14 '13 at 17:12
  • possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – michaelb958--GoFundMonica May 07 '14 at 00:16

1 Answers1

3

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.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150