简体   繁体   中英

PDO error: Fatal error: Insert value list does not match column list

I am inserting this into my database table and it is giving me a very weird error, my column count does match the value count (unless I am being very stupid). What else could cause this error? I have just moved onto PDO PHP.

My code is:

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

You should try this one

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

Notice that values in query are without single quote.

The issue is here:

INSERT INTO 10 yeah plus windows

table name do not contain space, as your name is yeah plus windows , instead of space pass _ and try again.

You not use whitespace in table name and also field.

Try this code,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM