dongtan7201 2014-08-27 12:31
浏览 79

PHP和SQL插入语句[重复]

This question already has an answer here:

So far I have created the table and getting a successful message. However when I go to insert into the table, I get: Error inserting sample record into 'Users': Column count doesn't match value count at row 1.

This is the code for creating the table:

mysql_select_db($dbName, $dbConnection);
$sql = "CREATE TABLE ".$dbTable." (ID int(6) auto_increment NOT NULL, Username varchar(20) NOT NULL, Password varchar(20) NOT NULL, UserType int(1) NOT NULL, FirstName varchar(15) NOT NULL, LastName varchar(15) NOT NULL, DOB DATETIME NOT NULL, Phone varchar(15) NOT NULL, Department varchar(15),PRIMARY KEY(ID))";
if(mysql_query($sql, $dbConnection))
{
    echo("Table '".$dbTable."' created<br />");
}
else
{
    echo("Error creating table '".$dbTable."': ".mysql_error()."<br />");
}   

And this is the code for inserting:

$sql = "INSERT INTO ".$dbTable." (Username, Password, UserType, FirstName, LastName, DOB, Department) VALUES (1, 'admin', 'admin', 1, 'Admin', 'Admin', '1900-01-01', '12345656', 'IT')";
if(mysql_query($sql, $dbConnection))
{
    echo("Added sample record to '".$dbTable."' table<br />");
}
else
{
    echo("Error inserting sample record into '".$dbTable."': ".mysql_error()."<br />");
} 
</div>
  • 写回答

5条回答 默认 最新

  • 普通网友 2014-08-27 12:34
    关注

    You forgot to addthe phone number column. The count of your insert values should match the count of the columns you specify in your insert query.

    评论

报告相同问题?

悬赏问题

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