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);

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度