简体   繁体   English

在一个MySQL列中插入多行时出现问题-PHP

[英]Issue while inserting multiple rows in one MySQL column- PHP

The query syntax is as follows: 查询语法如下:

INSERT INTO sent (username,password) VALUES 
 ('user','user2','user3','user4','user5','user6'),
 ('pass','pass2','pass3','pass4','pass5','pass6')

Resource: http://dev.mysql.com/doc/refman/5.5/en/insert.html 资源: http : //dev.mysql.com/doc/refman/5.5/en/insert.html

The mysql_error() always showing me this: mysql_error()总是向我显示以下内容:

Column count doesn't match value count at row 1

I have no idea what should I do. 我不知道该怎么办。 Now it's time to ask you about this. 现在是时候问你这个了。

You specified 2 columns with 6 values. 您为2列指定了6个值。 The number of columns and values has to match. 列数和值必须匹配。 What you want is this: 您想要的是:

INSERT INTO sent (username,password) VALUES ('user','pass'),('user2','pass2'),('user3','pass3'),('user4','pass4'),('user5','pass5'),('user6','pass6')

See the MySQL documentation for more details: 有关更多详细信息,请参见MySQL文档

INSERT statements that use VALUES syntax can insert multiple rows. 使用VALUES语法的INSERT语句可以插入多行。 To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas. 为此,请包括多个列值列表,每个列值括在括号内并用逗号分隔。 Example: 例:

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

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

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