我只是使用 PDO 将客户插入到我的表中,但是由于我自己或其他研究无法解释的事情,它变得过于复杂。它给出了错误代码:00000(这显然意味着成功)但实际上没有数据插入到数据库中,并且只有在查询失败时才应该输出错误,但错误是..成功?
$insertUser = $database->prepare("INSERT INTO customer (Surname, Forename, AddressRow1, AddressRow2, AddressRow3, AddressRow4, PostCode, Telephone, mobileNumber, Email, assignedGarage)
VALUES (:surname, :forename, :addressrow1, :addressrow2, :addressrow3, :addressrow4, :postcode, :telephone, :mobilenumber, :email, :assignedgarage)");
$insertUser->bindParam(':surname', $_POST['surname']);
$insertUser->bindParam(':forename', $_POST['forename']);
$insertUser->bindParam(':addressrow1', $_POST['addressrow1']);
$insertUser->bindParam(':addressrow2', $_POST['addressrow2']);
$insertUser->bindParam(':addressrow3', $_POST['addressrow3']);
$insertUser->bindParam(':addressrow4', $_POST['addressrow4']);
$insertUser->bindParam(':postcode', $_POST['postcode']);
$insertUser->bindParam(':telephone', $_POST['telephone']);
$insertUser->bindParam(':mobilenumber', $_POST['mobilenumber']);
$insertUser->bindParam(':email', $_POST['email']);
$insertUser->bindParam(':assignedgarage', $_SESSION['garageId']);
if(!$insertUser->execute()) {
$err[] = $database->errorCode();
}
elseif ($insertUser->rowCount() == 1) {
$id = $database->lastInsertId();
echo "<script type=\"text/javascript\">
<!--
window.location = \"updateUser.php?id=$id\"
//-->
</script>";
}
if(count($err)) {
echo "<p style=\"color:red;\">The following errors were detected:</p><br/>";
foreach ($err as $key => $error) {
echo "<p style=\"color:red;\">$error</p><br/>";
}
}
我一开始并没有定义我想要插入的所有列,但这不起作用,所以我预定义了它们。
我的桌子处于早期初级阶段。我有理由为手机/电话号码选择 varchars。