出於某種原因,我的PHP登錄腳本保持返回「無效的電子郵件/密碼組合」,但我知道我輸入正確的電子郵件地址和密碼。有沒有人看到我可能做錯了什麼?瞭解嵌套如果... Else語句
<?php
$email= $_POST['email'];
$password= $_POST['password'];
if (!empty($email) && !empty($password)) {
$connect= mysqli_connect("localhost", "root", "", "si") or die('error connecting with the database');
$query= "SELECT user_id, email, password FROM users WHERE email='$email' AND
password='$password'";
$result= mysqli_query($connect, $query) or die('error with query');
if (mysqli_num_rows($result) == 1) {
$row= mysqli_fetch_array($result);
setcookie('user_id', $row['user_id']);
echo "you are now logged in";
} else {
echo "invalid username/password combination";
}
} else {
echo" you must fill out both username and password";
}
?>
沒有好的縮進,很難理解你的代碼... – dqhendricks 2012-04-10 23:25:17
@dqhendricks剛剛編輯它! :-) – 2012-04-10 23:25:37
@dqhendricks它的源代碼很好,只是SO將標籤作爲4空格而不是標準8 – tobyodavies 2012-04-10 23:25:59