我正在使用框架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