Hello i am trying to build login page. There are two pages login.php and login2.php login.php has a form which accepts email and password from the user which are sent to login2.php using $.post() login2.php checks email and password in DB and a message is sent to login.php which is supposed to be displayed in having id="msg" Problem is that message is printed but after that the page is refreshed and the message is gone
login.php
<form>
<input type="radio" name="role" value="tbl_staff_details" checked>Institute/Branch
<input type="radio" name="role" value="tbl_student_details">Student/Parent
</br></br>
<div id="msg" style="color: red"></div>
<div class="form-group has-feedback">
<input type="email" class="form-control" placeholder="Email" id="mail">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" id="pwd">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> Remember Me
</label>
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat" id="signin">Sign In</button>
</div>
<!-- /.col -->
</div>
</form>
<script>
$(function(){
$("#signin").click(function(){
var mail = $("#mail").val();
var pwd = $("#pwd").val();
var role = $("input[name='role']:checked").val();
$.post("login2.php",
{
mail: mail,
pwd: pwd,
role: role
},
function(data,status){
$("#msg").text(data);
});
});
});
</script>
login2.php
<?php
$email=$_POST['mail'];
$pwd=$_POST['pwd'];
$table=$_POST['role'];
include_once 'conf.php';
if ($table=="tbl_staff_details") {
$q="select * from ".$table." where email=".$email." and pwd=".$pwd;
}
else{
$q="select * from ".$table." where stud_email='".$email."' and stud_pwd='".$pwd."' or stud_email='".$email."' and parent_pwd='".$pwd."'";
}
$r=mysqli_query($con,$q);
$ro=mysqli_num_rows($r);
if ($ro>0) {
echo "Success";
//header('location:test.php');
}
else{
echo "Email or password is wrong";
}
?>