I have written code for login and it redirects to deifferent pages according to user role but problem is that if there is wrong username or password it does not show error it simply shows blank page Please help me to show error meassge for wrong password or username.
loginform.php(html code)
<div id=“login_form”>
<form method="post" action="login.php">
<label>User Name:</label>
<input type="text" id="username" name="username" />
<label>Password:</label>
<input type="password" id="password" name="password" />
<label></label><br/>
<input type="submit" id="login" value="Login" />
<input type="button" id="cancel_hide" value="Cancel" />
</form>
</div>
<div id="shadow" class="popup"></div>
jquery:
$(document).ready(function(e) {
$(“#shadow”).fadeIn(“normal”);
$(“#login_form”).fadeIn(“normal”);
$(“#user_name”).focus();
$("#cancel_hide").click(function(){
$("#username").val()="";
$("#password").val()="";
});
$(“#username”).change(function(e) {
});
$(“#login”).click(function(){
if($("#username").val().length==0 && $("#password").val().length==0)
{
// $(this).next().html("Field needs filling");
$("#username").after('<span class="errorkeyup">Field cannot be empty</span>');
$("#password").after('<span class="errorkeyup">Field cannot be empty</span>');
//return false;
success = false;
}
});
});
login.php
<?php
session_start();
include(‘connection.php’);
$username = $_REQUEST[‘username’];
$password = $_REQUEST[‘password’];
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$login = mysql_query(“select * from userlogin where username = ‘$username’ and password = ‘$password’”);
$num_row = mysql_num_rows($login);
$row=mysql_fetch_array($login);
if($num_row == 1) {
echo “Login Successfull”;
$_SESSION[‘username’]=$row[‘username’];
$_SESSION[‘userrole’]=$row[‘usertype’];
if($row[‘usertype’]==‘admin’)
{
header(“Location:mainpage.php”);
//header(“Location:u2.php”);
exit();
}
else if($row[‘usertype’]==‘user’)
{
header(“Location:profilepg.php”);
exit();
}
}
else {
// exit();
/*echo '<script type="text/javascript">
document.getElementById("add_err").innerHTML= "Error";
window.history.back();
</script>';*/
//header("Location:loginform.php");
}
?>