我正在使用框架7,我試圖使用PHP(PDO)和Ajax登錄,但每次它出現「登錄失敗」甚至如果在電子郵件和密碼輸入中插入了正確的數據,也不會出現錯誤,我可以使用PHP(PDO)進行註冊,並且一切都很順利,但無法登錄,請告知有什麼問題我的代碼我無法登錄使用PHP(pdo)&AJAX
index.php
<div class="pages navbar-through" class="login-screen">
<div data-page="index" class="page no-navbar no-toolbar">
<div class="page-content" style="background:url(img/bg1.png) ;background-
size: 100%">
<div class="content-block-title center">
</div>
<span style="float: right;color: white;margin:20px;font-size: 20px">
<b>عربي</b></span>
<div class="list-block" style="margin:100px 70px auto 70px;">
<img src="img/logo2.png" style="height: 55px ;width: 100%;margin-bottom:
60px;text-align: center;">
<div class="item-input" style="border-bottom: 1px solid gray">
<input type="text" placeholder="Email" id="email" name="email" style="font-
size: 15px;color: white;" required>
</div>
<div class="item-input" style="border-bottom: 1px solid gray;margin-top:
10px">
<input type="password" name="password" placeholder="password" id="password"
style="font-size: 15px;color: white"; required>
</div>
<div style="text-align: center ;margin-top: 30px">
<a href="#" style="color: #00bcd4 ;font-size: 15px">Forgot your password ?
</a>
<span id="login_message"><img src="img/ajax-loader.gif" style="display:
none;"></span>
<center><button style="margin-top: 20px; background-color: #00bcd4;border-
radius: 0px;height: 45px; width: 240px; color: white; text-align: center;"
name="login-btn" class="list-button" id="login-btn" name="login-btn">Login</button></center>
<p style="color: white;font-size: 13px;margin-top: 40px"> You don't have
account? </p>
<a href="registeration.php" style="color: #ffeb3b ;font-size:
13px">REGISTER</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
my-App.js
$(document).ready(function() {
$('#login-btn').click(function() {
var email = $('#email').val();
var password = $('#password').val();
if($.trim(email).length > 0 && $.trim(password).length > 0)
{
$.ajax({
url:"login.php",
method: "POST",
data: {email:email, password:password},
cache: false,
beforeSend:function()
{
$('#login-btn').val("connecting...");
},
success:function(data){
if(data){
myApp.alert('Login successful');
}
else{
myApp.alert('Login failed');
}
}
});
}
});
});
login.php
<?php
require_once 'config.php';
session_start();
if(isset($_POST['login-btn'])){
$email = $_POST['email'];
$password = $_POST['password'];
$select = $db_con->prepare("SELECT * FROM user WHERE email='$email' and
password='$password'");
$select->setFetchMode(PDO::FETCH_ASSOC);
$select->execute();
$data=$select->fetch();
if($data['email']!=$email and $data['password']!=$pass)
{
echo "invalid email or password";
}
elseif($data['email']==$email and $data['pass']==$pass)
{
$_SESSION['email']=$data['email'];
echo "successful";
}
}
?>
你'prepare'然後查詢失敗'bindParam'就可以了,讓'prepare'毫無意義。您的代碼易受SQL注入攻擊。 – IsThisJavascript
if ifset isset($ _ POST ['login-btn'])){' - 你沒有發送一個名爲''''的參數,如果你想要求助,至少做一個最小的努力並且適當地調整你的代碼 –
'登錄btn'與您的AJAX請求,所以這將永遠是錯誤的... – CBroe