Reputation: 921
Sorry for the dumb question, but I'am not able to figure out my typo:
INSERT INTO lunchmenu (rid, date, repeat, approved) VALUES ('32', '2011-10-18', '3', '0')
I get an mySQL (v5) error saying
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 'repeat, approved) VALUES ('32', '2011-10-18', '3', '0')' at line 1
My table structure is
Field Type Size - NULL - Key - Attribute - Default - Extra
1. id int 11 no PI unsigned auto_increment
2. rid int 11 no unsigned
3. date date no I
4. repeat tinyint 1 no unsigned 0
5. approved int 10 no I unsigned 0
Any hint for me? Thanks.
Upvotes: 0
Views: 55
Reputation: 1683
DATE
and REPEAT
are reserved keywords in MySQL, try
INSERT INTO lunchmenu AS l (l.rid, l.date, l.repeat, l.approved) VALUES ('32', '2011-10-18', '3', '0')
This would make your database parse them explicitly as columns.
Upvotes: 0
Reputation: 57573
Try this:
INSERT INTO lunchmenu (rid, `date`, `repeat`, approved)
VALUES (32, '2011-10-18', 3, 0)
Date
and repeat
are reserved words, so you have to use backticks for them.
Other reserved words can be found here
Upvotes: 1
Reputation: 12586
The problem is that REPEAT
and DATE
are a reserved and you need to escape it using backticks ` to use it as a column.
INSERT INTO `lunchmenu` (`rid`, `date`, `repeat`, `approved`) VALUES ....
It's a good practise to always escape column and table names.
Upvotes: 1
Reputation: 449425
date
and repeat
are reserved words in mySQL.
Wrap them in backticks, or use different column names.
Upvotes: 3