php - PDO错误: Fatal error: Insert value list does not match column list

标签 php mysql pdo

我将其插入到我的数据库表中,它给了我一个非常奇怪的错误,我的列计数确实与值计数匹配(除非我非常愚蠢)。还有什么可能导致此错误?我刚刚转向 PDO PHP。

我的代码是:

$sql2 = "INSERT INTO `10 yeah plus windows`(`adults in property`, `age`, `alternative number`, `date of appointment`, `debt`, `employment status`, `energy spend`, `homeowner`, `lead id`, `notes`, `number of doors`, `number of windows`, `time of appointment`, `windows last replaced`) VALUES ('?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?')" ;
                                    $result = $conn->prepare($sql2);
                                    $count = $result->execute(array($_POST['adultsinproperty'], $_POST['age'], $_POST['alternativenumber'], $_POST['appdate'], $_POST['debt'], $_POST['employmentstatus'], $_POST['energy'], $_POST['homeowner'], $last_id, $_POST['notes'], $_POST['number_of_doors'], $_POST['number_of_windows'], $_POST['apptime'], $_POST['windowslastreplaced']));

最佳答案

你应该尝试一下这个

$sql2 = "INSERT INTO `10 yeah plus windows`(`adults in property`, `age`, `alternative number`, `date of appointment`, `debt`, `employment status`, `energy spend`, `homeowner`, `lead id`, `notes`, `number of doors`, `number of windows`, `time of appointment`, `windows last replaced`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" ;
                                $result = $conn->prepare($sql2);
                                $count = $result->execute(array($_POST['adultsinproperty'], $_POST['age'], $_POST['alternativenumber'], $_POST['appdate'], $_POST['debt'], $_POST['employmentstatus'], $_POST['energy'], $_POST['homeowner'], $last_id, $_POST['notes'], $_POST['number_of_doors'], $_POST['number_of_windows'], $_POST['apptime'], $_POST['windowslastreplaced']));

请注意,查询中的值不带单引号。

关于php - PDO错误: Fatal error: Insert value list does not match column list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44676213/

相关文章:

PHP PDO 产生 "Array"值而不是实际值

javascript - 无法加载资源: the server responded with a status of 405 (Method Not Allowed)

php - mysql_fetch_array 只返回一行

php - 使用 PHP 和 MySQL 标记页面

php - PHP PDO错误处理暂停执行

php - 在 EXTRACT() 查询中使用 PDO 参数

php - 如何保护管理文件夹php

javascript - 将结果从 php if 语句传递到 javascript/html

php - 关于 Centos/PCI DSS 合规性的 CVE-2011-1092

mysql - 将自定义字段添加到基本客户端集成选项