0
我通過使用下列Ajax和庫MySQLi預處理語句
var login = $.ajax({
type: "POST",
url : "assets/app/users.php",
cache: false,
data: data,
beforeSend: function() {
console.log(data);
},
success: function() {}
});
login.done(function(html) {
if(html=='true'){
window.location.replace('app.php');
}
else {
$("#loginRequest").before('<div class="alert alert-danger err" role="alert">Email or Password Is Not Correct</div>');
}
});
越來越登錄的結果有問題
有問題,這是在服務器端的PHP我hvae
$email = $_POST['email'];
$pass = $_POST['pass'];
$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
$sql = "SELECT id, email, fname, lname, type FROM users WHERE `email`=? AND `pass`=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param('ss', $email,$pass);
$stmt->execute();
$stmt->bind_result($theId,$theEmail,$theFName,$theLname,$theType);
if($stmt->num_rows > 0){
$stmt->fetch();
echo 'true';
$_SESSION['LOGIN_STATUS'] = true;
$_SESSION['fname'] = $theFName;
}
else{
echo 'false';
}
我正在向服務器發送正確的數據,因爲我已經在beforeSend(){}
和$_POST['email'];
上測試了它們,它們都返回了interred值。我也使用普通的SQL查詢來測試數據庫,該查詢功能正常,但我在控制檯中得到了false
有效和無效憑據!
非常感謝Barmar, – Behseini