插入数据库失败

时间:2015-09-29 08:18:39

标签: php mysql pdo

此代码根本不会抛出任何错误,但是当我将结果检查到数据库时,没有添加新行。请帮忙

$stmt = $conn->prepare("INSERT INTO users (first_name, last_name, dept_id, contact_no, email, username, password, position_apply_first, position_apply_second, date_of_application, city_address, permanent_address, residence_no, office_no, date_of_birth, marital_status, religion, sex, sss_no, tin_no, pagibig_no, philhealth_no, prc_no, hobbies, language_fair, language_fluent) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssssssssssssssssssssssss", $first_name, $last_name, $department, $contact_no, $email, $user, $pass, $apply_first, $apply_second, $date_of_application, $city_address, $permanent_address, $residence_no, $office_no, $date_of_birth, $marital_status, $religion, $sex, $sss_no, $tin_no, $pagibig_no, $philhealth_no, $prc_no, $hobbies, $language_fair, $language_fluent);
// insert one row
$first_name = $_POST["reg-firstname"];
$last_name = $_POST["reg-lastname"];
$department = $_POST["reg-dept"];
$contact_no = $_POST["reg-mobile"];
$email = $_POST["reg-emailAddress"];
$user = $_POST["reg-username"];
$pass = $_POST["reg-password1"];
$apply_first = $_POST["first_choice"];
$apply_second = $_POST["second_choice"];
$date_of_application = $_POST["reg-applicationdate"];
$city_address = $_POST["reg-cityaddress"];
$permanent_address = $_POST["reg-permanentaddress"];
$residence_no = $_POST["reg-residence"];
$office_no = $_POST["reg-office"];
$date_of_birth = $_POST["reg-dateofbirth"];
$marital_status = $_POST["reg-maritalstatus"];
$religion = $_POST["reg-religion"];
$sex = $_POST["reg-sex"];
$sss_no = $_POST["reg-sssno"];
$tin_no = $_POST["reg-tinno"];
$pagibig_no = $_POST["reg-pagibigno"];
$philhealth_no = $_POST["reg-philhealthno"];
$prc_no = $_POST["reg-prcno"];
$hobbies = $_POST["reg-hobbies"];
$language_fair = $_POST["reg-languagefair"];
$language_fluent = $_POST["reg-languagefluent"];

$stmt->execute();
$conn->close();

1 个答案:

答案 0 :(得分:2)

  

此代码不会引发任何错误

因为您没有检查任何错误 ,我们当然会猜测它是什么,而您可以轻松检查错误并找出答案。

printf("Error: %s.\n", $stmt->error);

<强> Koala