Simple MySQL INSERT Error

No doubt, I missed something really simple, but I just do not see a problem with this query, which causes the following error:

SQL query:

INSERT INTO ads(
    ad_id, author, ad_date, category, title,
    description, condition, price, fullname,
    telephone, email, status, photo, photothumb
)
VALUES (
    NULL , 'justal', '1225790938', 'Windsurf Boards',
    'test', 'test', 'Excellent', '12', 'test',
    'test', 'test', '', '', ''
);

MySQL said: Documentation
#1064 - 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 ''ad_id', 'author',
'ad_date', 'category', 'title', 'description',
'condition', '' at line 1

Can someone with fresh eyes see the problem?

Thanks Al.

+3
source share
3 answers

Shouldn't reverse ticks be used instead of single quotes in column names?

INSERT INTO ads( `ad_id`, `author`, `ad_date`, `category`, `title`, `description`, `condition`, `price`, `fullname`, `telephone`, `email`, `status`, `photo`, `photothumb` )
VALUES (
NULL , 'justal', '1225790938', 'Windsurf Boards', 'test', 'test', 'Excellent', '12', 'test', 'test', 'test', '', '', ''
);
+3
source

It is possible that CONDITION is a mysql keyword and is not resolved as a column name.

http://dev.mysql.com/doc/refman/5.1/en/declare-conditions.html

You definitely don’t need "or"

+2
source

. MySQL , SQL, .

For column names, you usually do not quote them at all. If you need to - and you don’t have anyone else - quote them with backquote (`) or set it in strict ANSI mode (ANSI_QUOTES) and use double quotes.

+1
source

Source: https://habr.com/ru/post/1699095/


All Articles