在检查表格中的电子邮件和密码之后,它会进入studentDashBoard.php文件。但每次我得到错误,并给出错误的id或psd错误。
这是我的html标记:
login.php
:
<form action="login.php" id="LoginForm" name="LoginForm" method="post" onsubmit=" return validate();">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-user"></span></span>
<input type="email" name="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email" required>
</div>
<p id="statusEmail"></p>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1"><span class="glyphicon glyphicon-star"></span></span>
<input type="password" name="password"class="form-control" id="exampleInputPassword1" placeholder="Password" required>
</div>
<p id="statusPsd"></p>
</div>
<hr/>
<p id="status"></p>
<button type="button" class="btn btn-success"><span class="glyphicon glyphicon-arrow-left">Back</button>
<button type="submit" name="submit" id="loginButton" class="btn btn-primary"><span class="glyphicon glyphicon-lock">Login</button>
<p><br/></p>
<p id="notice"> If not registered yet</p><br/>
<button type="button" id="SignUp" class="btn btn-danger">SingUp</button>
</form>
这是jQuery代码:
$(document).ready(function(){
$("#loginButton").click(function(e){
email=$("#exampleInputEmail1").val();
e.preventDefault();
password=$("#exampleInputPassword1").val();
$.ajax({
type: "POST",
url: "StudentLogin.php",
data: "email="+email+"&password="+password,
success:function(html)
{
if(html==true){
---> this function is not working while I am login with correct data
window.location="studentDashBoard.php";
}
else{
$("#status").html("<p>worng id or psd</p>");
}
}
});
});
});
和StudentLogin.php
代码
<?php
$link = mysqli_connect('localhost','root','','users');
if (!$link) {
die('Could not connect to MySQL: ' . mysqli_error($link));
}
if(isset($_POST['submit']))
{
echo "submit";
$email=$_POST['email'];
$password=$_POST['password'];
$sql = "SELECT * FROM student WHERE email='$email' AND password='$password' ";
$query = mysqli_query($link,$sql);
$result= mysqli_num_rows($query);
if($result > 0)
{
echo 'true';
}
else
{
echo 'false';
}
}
mysqli_close($link);
?>
studentDashBoard.php
文件只是打印“hi”而已。
如果您需要更多详情,请与我们联系
答案 0 :(得分:1)
而不是:
if(isset($_POST['submit'])){
}
在studentLogin.php
文件中,我更改为
if( isset($_POST['email']) && isset($_POST['password']) )
{
现在它可以工作
答案 1 :(得分:0)
尝试使用您的if
条件,如下所示:
if(html=="true")
{}
答案 2 :(得分:0)
替代
success:function(html)
{
if(html==true)
{
}
}
类似
success:function(html)
{
if($('#result').html(html)==true)
{
{
}