简体   繁体   中英

Mysql wont insert into database

As far as I can see my SQL code is formatted correctly, it seems to just be refusing to insert into the database. this is my code:

 INSERT INTO `writings`(`cover`, `pages`) VALUES(['test'], [10]);

i also tried

INSERT INTO `writings`(cover, pages) VALUES(['test'], [10]);

&

INSERT INTO `writings`(cover, pages) VALUES('test', 10);

I encounter this error "#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 '['test'], [10])' at line 1 "

table name is correct, aswell as column names. Any help would be fantastic! :)

As already pointed out on the comment

MySQL does not use [] around values

So you should try this way

   INSERT INTO `writings`(`cover`, `pages`) VALUES('test', 10);

OR if you want the cover and pages value as an string of array notation

INSERT INTO `writings`(`cover`, `pages`) VALUES("['test']", "[10]");
INSERT INTO writings(cover, pages) VALUES('test', 10);

This is worked for inserting data in mysql. Basic syntax problem in your query, nothing else. Make sure table name and field name is proper match with database & values are of same datatype you mention while created table.

First two queries are incorrect as mentioned above.
Third query is absolutely correct and must work. If it doesn't, try using INSERT ... SET syntax:

INSERT INTO `writings` SET cover = 'test', pages = 10;

Please try like this :

Sql Query:

INSERT INTO writings (cover, pages) VALUES ('test', 10);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM