我正在编写一些代码来使用 PDO 将一些数据输入到 mysql 数据库中。此代码有效(验证数据是否全部存在):
echo $usertype . '<br>';
echo $firstname . '<br>';
echo $lastname . '<br>';
echo $company . '<br>';
echo $jobtitle . '<br>';
echo $address . '<br>';
echo $email . '<br>';
echo $telephone . '<br>';
echo $mobile . '<br>';
echo $dobday . '<br>';
echo $dobmonth . '<br>';
echo $dobyear . '<br>';
echo $gender . '<br>';
echo $ethnicity . '<br>';
echo $password . '<br>';
echo $credits . '<br>';
但是这段代码没有(我已经检查了数据库连接并且它确实连接并且名为 users 的表确实存在):
$STH = $dbh->prepare("INSERT INTO users (firstname, lastname, company, jobtitle, usertype, address, email, telephone, mobile, dobday, dobmonth, dobyear, gender, ethnicity, password, credits) values (:firstname, :lastname, :company, :jobtitle, :usertype, :address, :email, :telephone, :mobile, :dobday, :dobmonth, :dobyear :gender, :ethnicity, :password, :credits)");
$STH->bindParam(':firstname', $firstname);
$STH->bindParam(':lastname', $lastname);
$STH->bindParam(':company', $company);
$STH->bindParam(':jobtitle', $jobtitle);
$STH->bindParam(':usertype', $usertype);
$STH->bindParam(':address', $address);
$STH->bindParam(':email', $email);
$STH->bindParam(':telephone', $telephone);
$STH->bindParam(':mobile', $mobile);
$STH->bindParam(':dobday', $dobday);
$STH->bindParam(':dobmonth', $dobmonth);
$STH->bindParam(':dobyear', $dobyear);
$STH->bindParam(':gender', $gender);
$STH->bindParam(':ethnicity', $ethnicity);
$STH->bindParam(':password', $password);
$STH->bindParam(':credits', $credits);
try{
$STH->execute();
redirect_to(formsuccess.php);
}
catch(PDOException $e) {
echo "I'm sorry, Dave. I'm afraid I can't do that.";
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
redirect_to(databaseentryfail.php);
}
请你能帮我解决这个问题,我知道我错过了一些愚蠢的事情......
霍克斯顿