-1
我有一個SQL表格照顧我網站的成員列表。但是,註冊新用戶時,數據不會插入表中。沒有錯誤顯示,因爲我在我的代碼中檢查了幾次。SQL - 未插入數據,無錯誤
if (empty($error_msg)) {
// Create hashed password using the password_hash function.
// This function salts it with a random salt and can be verified with
// the password_verify function.
$password = password_hash($password, PASSWORD_BCRYPT);
// Insert the new user into the database
if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password) VALUES (?, ?, ?)")) {
$insert_stmt->bind_param('sss', $username, $email, $password);
// Execute the prepared query.
if (!$insert_stmt->execute()) {
header('Location: ./error.php?err=Registration failure: INSERT');
}
header('Location: ./register_success.php?');
}
}
該代碼執行到最後,我被重定向到register_success。 我知道這不是因爲我在代碼中的某處輸入了錯誤的數據庫憑據,而是使用相同的憑據將數據發送到同一數據庫(它們保存在另一個文件中),並且它工作得很好。
編輯: 尼克·科恩斯說,刪除第二個「標題」後,我被重定向到錯誤頁面,這意味着執行有問題。不過,我不知道爲什麼......
檢查的代碼在哪裏顯示任何錯誤?此外,無論是否有錯誤,它都將重定向到register_success.php,因爲您的第二個「header()」函數將會執行,而且將覆蓋第一個。 –
@NickCoons哦,我不知道第二個會覆蓋第一個。然後,在那種情況下,我只刪除了第二個,然後我被重定向到錯誤頁面,這意味着執行有問題。不過,我不知道爲什麼。 – Zerox029
看看這個輸出發生的錯誤:http://php.net/manual/en/mysqli.error.php –