douruduan8812 2014-06-15 23:01
浏览 24
已采纳

在一个MySQL列中插入多行时发出问题 - 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

The mysql_error() always showing me this:

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.

  • 写回答

1条回答 默认 最新

  • duanbeng8872 2014-06-15 23:04
    关注

    You specified 2 columns with 6 values. 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:

    INSERT statements that use VALUES syntax can insert multiple rows. 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);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?