douqianmin5367 2015-04-24 22:52
浏览 336

插入值列表与列列表不匹配,语句和DB是否对应?

I'm working on this page where other users are added, when I want to insert a new user, this is what comes up:

 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[21S01]: Insert value list does not match column list: 
1136 Column count doesn't match value count at row 1' in /Applications/XAMPP/xamppfiles/htdocs/app/classes/class.users.php:96 Stack trace: #0 

/Applications/XAMPP/xamppfiles/htdocs/app/classes/class.users.php(96): PDO->prepare('INSERT INTO use...') #1 

/Applications/XAMPP/xamppfiles/htdocs/public/pages/nieuweklant.tpl(4): DeGier\Core\Users::addCus() #2 

/Applications/XAMPP/xamppfiles/htdocs/app/classes/class.template.php(20): include('/Applications/X...') #3 

/Applications/XAMPP/xamppfiles/htdocs/app/classes/class.template.php(48): DeGier\Core\Template::getPage('nieuweklant') #4 

/Applications/XAMPP/xamppfiles/htdocs/index.php(11): DeGier\Core\Template::render('nieuweklant') #5 {main} 

thrown in /Applications/XAMPP/xamppfiles/htdocs/app/classes/class.users.php on line 96

Normally, this pops up when I've missed a comma somewhere in the prepare statement, or if the statement isn't corresponding to my DB table, but this time, I believe that none of that has happened.

This is the PDO Statement:

    $q = self::$connection->prepare('INSERT INTO users VALUES ("", 

:fname, :lname,

 :company, :telephone, :email, :adress, :zipcode, 

    :country, :note)');


    $q->execute(array(":fname" => $_POST['voornaam'], ":lname" => 

$_POST['achternaam'], ":company" => $_POST['bedrijf'],  ":telephone" => 

$_POST['telefoon'], ":email" => $_POST['email'], ":adress" => 

$_POST['adres'], ":zipcode" => $_POST['postcode'], ":country" => 

$_POST['land'], ":note" => $_POST['aantekening']));

I don't believe there's anything wrong there.

Here is my DB table:

TABLE

Again, I believe it all matches up.

So, how is it possible that such a big error comes up for none of the default reasons?

Thanks.

  • 写回答

1条回答 默认 最新

  • drwn65609 2015-04-27 08:15
    关注

    You could try writing in the columns that you wish to insert to. Since your ID is AUTO INCREMENT, it might go wrong when you try to insert an empty string to that field.

       $q = self::$connection->prepare('INSERT INTO users (firstname, lastname, company, phone, email, adress, zipcode, country, note) VALUES ("", 
    
    :fname, :lname,
    
     :company, :telephone, :email, :adress, :zipcode, 
    
        :country, :note)');
    
    
        $q->execute(array(":fname" => $_POST['voornaam'], ":lname" => 
    
    $_POST['achternaam'], ":company" => $_POST['bedrijf'],  ":telephone" => 
    
    $_POST['telefoon'], ":email" => $_POST['email'], ":adress" => 
    
    $_POST['adres'], ":zipcode" => $_POST['postcode'], ":country" => 
    
    $_POST['land'], ":note" => $_POST['aantekening']));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100