Php PDO错误:致命错误:插入值列表与列列表不匹配

Php PDO错误:致命错误:插入值列表与列列表不匹配,php,mysql,pdo,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`, `homeo

我将它插入到我的数据库表中,这给了我一个非常奇怪的错误,我的列计数与值计数匹配(除非我非常愚蠢)。还有什么可能导致此错误?我刚刚转到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']));
请注意,查询中的值没有单引号。

问题在于:

INSERT INTO 10 yeah plus windows

表名不包含空格,因为您的名称是
耶加windows
,而不是空格传递

表名和字段中不使用空格

试试这个代码

$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']));

谢谢,我真不敢相信我有多傻,谢谢你们。