views:

48

answers:

1

Here is my table:

id               int(11)
name             varchar(255)
description      text       
highest_bidder   int(11)
value            varchar(255)
group            int(11)

I originally didn't have the group field in there but added it later.

Anyway, I go to insert into the database using the following snippet:

INSERT INTO name_of_table_removed
(id,name,description,highest_bidder,group,value)
VALUES
(2,"...","...",0,3,"$45.99")

And I get an 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 'group,value) VALUES (2,"...","...",0,3,"$45.99")' at line 1

What am I missing?

+3  A: 

Group is a reserved word. Escape the field as :

`group`

..Or rename the field.

Chaos
Ah! I am such a idiot! That also explains why phpMyAdmin would work with it but my code could not.
George Edison
Yep - tools like phpMyAdmin escape almost everything, just in case.
Chaos
I noticed that it always did that... now I know why. Also, even SO picked up on the problem - look above and you can see that 'group' is highlighted as a reserved word.
George Edison
I personally recommend escaping rather than renaming. Otherwise, you may pollute your web application with things like $result->group_ . Stop it at the source :) By the way, in PostgreSQL, you would use double quotes (as in "group") instead of backticks.
Joey Adams
It's okay. I renamed it to category and that is more in line with the app anyway.
George Edison