這一整天都在工作,訪問了很多論壇,並接受了很多建議,但似乎仍然有些問題。無法弄清楚爲什麼我的查詢不會通過
我試圖通過SQL提交查詢,一旦所有正確的用戶信息被輸入,然後重定向用戶返回index.html作爲一個'登錄'用戶一旦完成。
下面是代碼:
error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
//setup database connection
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$mysql_database = "21st";
$conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Could not connect database");
mysqli_select_db($conn, $mysql_database) or die("Could not select database");
//get user info
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
//if passwords are equal and longer than 5 characters, and username is longer than 4 characters
if ($password != $password2) || (strlen($username)) < 4 || (strlen($password < 5)) {
header('Location: index.html');
} else {
//encrypt passwords
$password = md5($password);
$password2 = md5($password2);
//sanitize email
$sanitized_email = filter_var($email, FILTER_SANITIZE_EMAIL);
//insert query into database
$sql = "INSERT INTO members (username, email, password) VALUES ('$username','$email','$password')";
mysqli_query($conn, $sql);
//redirect user to index.html once all is completed
header('Location: index.html');
exit();
}
}
你得到任何錯誤? –
md5不安全的密碼,[看到這個例子](https://stackoverflow.com/questions/401656/secure-hash-and-salt-for-php-passwords) – kero
你是否檢查過列中的列名數據庫是否與您在SQL查詢中指定的列名相同? –