Jump to content

SQL syntax error in MySQL

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
tomitzel

tomitzel

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
Hello,
I'm trying to insert a new record in the database tabel "movie_group" witht he following query:
$sql = "INSERT INTO movie_group (movie, group) VALUES ('$movie_id','22')";

but I get the following error message:
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 'group) VALUES ('8018','22')' at line 1

The fields "movie" and "group" exist in the tabel. The other fields of the tabel have default values.
Do you know whats wrong with the query?

Thank you.

#2
DarkLordoftheMonkeys

DarkLordoftheMonkeys

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
You don't have to address the columns by name. You can just set the values in the order that the fields appear, for instance:
INSERT INTO movie_group VALUES ('$movie_id','22');

MySQL never gives explicit error messages unless you make a common, easily detectable mistake like querying a column that doesn't exist.

I don't know what is with the quotes around the query. Are you using an API?
Life's too short to be cool. Be a nerd.

#3
tomitzel

tomitzel

    Learning Programmer

  • Members
  • PipPipPip
  • 44 posts
I fixed this, the problem was that "group" is a rezerved word, so I need to write it like this `group`.