简体   繁体   English

MySQL不会插入数据库

[英]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. 据我所知,我的SQL代码格式正确,似乎只是拒绝插入数据库。 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 " 我遇到此错误“#1064-您的SQL语法有错误;请在第1行的'['test'],[10])'附近使用与MySQL服务器版本相对应的手册以获取正确的语法以使用正确的语法”

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 MySQL不在值周围使用[]

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 或者, 如果您希望Cover和pages值作为数组符号的字符串

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

This is worked for inserting data in mysql. 这用于在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 ... SET语法:

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

Please try like this : 请尝试这样:

Sql Query: SQL查询:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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