我已经制作了一个简单的登录表单以及会话。 当我输入用户名和密码以登录系统时。 我没有收到任何错误,但登录不起作用。 如果我输入正确的用户名和密码,它就不会进入索引.php如果我输入错误的用户名和密码,则不会显示错误消息。 如果我查看控制台错误没有显示。
**Form Design**
<form id="frmlogin">
<div class="form-group">
<input type="text" class="form-control" name="email" id="email" placeholder="Email">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" id="password" placeholder="Password">
</div>
<div id="err">
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
</div>
</div>
<div class="col-xs-4">
<button type="button" class="btn btn-primary btn-block btn-flat" onclick="login()">Sign In</button>
</div>
</div>
</form>
JQuery 验证
function login() {
var data = $("#frmlogin").serialize();
$.ajax({
type: 'POST',
url: 'validate_login.php',
data: data,
success: function (response) {
if (response == 1) {
window.location.replace('index.php');
}
else if (response == 3) {
$("#err").hide().html("Email or password incorrect. Please check").fadeIn('slow');
}
else if (response == 0) {
$("#passerr").hide().html("Account is not activated. please contact Administrator").fadeIn('slow');
}
}
});
}
validate_login.php
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
session_start();
include("db.php");
$uname=$_POST['email'];
$password= $_POST['password'];
$stmt = $conn->prepare("SELECT id,username,password from login WHERE username=? and password=?");
$stmt->bind_param("ss", $uname,$password);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id,$username,$password);
$stmt->fetch();
if ($stmt->num_rows == 1) {
if ($stat==0){//invert of this
echo 0;//email not verified
}else{
$_SESSION["id"]=$id;
$_SESSION["username"]=$username;
echo 1;
}
} else {
echo 3;//use pass incorrect
}
$stmt->close();
}
您没有在表单标记中给出操作方法。添加表单方法="发布">