我是PHP
的新手。我正在尝试使用PHP
和Ajax
到logging
将项目编码到另一个页面。但是在Ajax query
中,某些部分没有执行,这意味着它会检查Ajax query
部分中的所有内容,但是只要成功,它们就会在"Wrong combination"
中始终显示alert
。
这是我尝试过的代码:
登录页面HTML
为:
form method="POST" class="form-signin">
<div class="account-logo">
<img src="assets/img/logo-dark.png" alt="">
</div>
<div class="form-group">
<label> Email</label>
<input type="email" name="email" id="email" autofocus="" class="form-control">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" id="password" class="form-control">
</div>
<div class="form-group text-right">
<a href="forgot-password.html">Forgot your password?</a>
</div>
<div class="form-group text-center">
<input type="button" onClick="sendContact();" class="btn btn-primary account-btn" name="login" value="DO LOGIN" id="login_button">
<!-- <button type="submit" class="btn btn-primary account-btn">Login</button> -->
</div>
<div class="text-center register-link">
Don’t have an account? <a href="register.html">Register Now</a>
</div>
</form>
Ajax
部分为:
function sendContact() {
var email = $('#email').val();
var password = $('#password').val();
var data = {
"email": email,
"password": password,
};
jQuery.ajax({
data: data,
url: "auth/log.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
success: function(data)
{
if(data==='success'){
window.location.replace('index.php');
}
else{
alert('Wrong combination');
}
}
});
// window.location.replace('index.php');
}
log.php页面将是
<?php
include "dbconnection.php";
session_start();
// $email=$_POST['email'];
// $password=$_POST['password'];
$select_data="select * from users where email='". $_POST['email']."' and password='".$_POST['password']."'";
$results= $conn->query($select_data);
if($results->num_rows>0){
$_SESSION["loggedin"] = true;
$_SESSION["user"] = $email;
echo 'success';
}else{
echo 'fail';
}
?>
这里有人可以帮我吗