2 回答

TA貢獻1998條經驗 獲得超6個贊
您在第二個查詢中出錯,您沒有正確引用密碼。也就是說,您根本不需要第二個查詢,因為電子郵件字段已經在第一個結果中。你知道它只有一行因為你檢查mysqli_num_rows($results) == 1
if (count($errors) == 0) {
$password = base64_encode($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$user_data = mysqli_fetch_assoc($results);
$_SESSION['username'] = $username;
$_SESSION['email'] = $user_data['email'];
$_SESSION['password'] = $password;
$_SESSION['success'] = "You are now logged in";
if ($_SESSION['page'] == "account.php"){
header('location: account.php');
}
else{
header('location: index.php');
}
}else {
array_push($errors, "Wrong username/password combination");
}
}
最后要注意的是,請記住 base64 不是存儲密碼的理想函數,而使用一些散列函數可能是個好主意。

TA貢獻1828條經驗 獲得超3個贊
登錄成功后,您應該會收到您的電子郵件。
$password = base64_encode($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$row = mysqli_fetch_assoc($result);
$_SESSION['username'] = $username;
$_SESSION['email'] = $row['email'];
}
- 2 回答
- 0 關注
- 264 瀏覽
添加回答
舉報