无法插入数据库:列计数与第1行的值计数不匹配

时间:2015-08-18 22:14:18

标签: php mysql sql database

我在hte相同的数据库中有一个表,它与语法或格式没有区别。但是我得到了上面提到的错误?我已经做了我所知道的一切来修复它,但不确定我做错了什么。我也有结构图像。

$sql = "INSERT INTO `FormInfo` (`first_name`, 
                                `last_name`, 
                                `company`, 
                                `address`, 
                                `province`, 
                                `postal`, 
                                `telephone`, 
                                `fax`, 
                                `email`, 
                                `comment`) 
                        VALUES ('$good_data[first_name]',
                                '$good_data[last_name]',
                                '$good_data[company]',
                                '$good_data[address]',
                                '$good_data[province]',
                                '$good_data[postal]',
                                '$good_data[telephone]',
                                '$good_data[email]',
                                '$good_data[comment]')";
mysqli_query($cxn, $sql) or die ("Couldn't insert into Database: " . mysqli_error($cxn));

enter image description here

我在这里缺少什么?

3 个答案:

答案 0 :(得分:1)

您错过了$good_data[fax]参数

编辑:另外,请考虑你在阵列中调用对象的方式是不好的做法。有关详细信息,请参阅this

答案 1 :(得分:0)

尝试改变,

$sql = "INSERT INTO `FormInfo` (`first_name`, `last_name`, `company`, `address`, `province`, `postal`, `telephone`, `fax`, `email` ,`comment`) VALUES ('$good_data[first_name]', '$good_data[last_name]', '$good_data[company]', '$good_data[address]', '$good_data[province]', '$good_data[postal]', '$good_data[telephone]', '$good_data[email]', '$good_data[comment]')";

$sql = "INSERT INTO `FormInfo` (`first_name`, `last_name`, `company`, `address`, `province`, `postal`, `telephone`, `fax`, `email` ,`comment`) VALUES ('$good_data[first_name]', '$good_data[last_name]', '$good_data[company]', '$good_data[address]', '$good_data[province]', '$good_data[postal]', '$good_data[telephone]', '$good_data[email]', '$good_data[comment]', '$good_data[fax]')";

答案 2 :(得分:0)

您缺少fax列的插入值:

$SQL = "INSERT INTO `FormInfo` 
       (`first_name`, 
      `last_name`,
       `company`, 
       `address`, 
       `province`, 
       `postal`, 
       `telephone`, 
       `fax`, 
       `email`,
       `comment`
       ) 
      VALUES (
      '$good_data[first_name]', 
      '$good_data[last_name]', 
      '$good_data[company]', 
      '$good_data[address]', 
      '$good_data[province]', 
      '$good_data[postal]', 
      '$good_data[telephone]', 
      '$good_data[fax]',   
      '$good_data[email]', 
      '$good_data[comment]'
      )";