You may use jQuery ajax to check valid username/password so that you can use the dialog box to show the error messages.
Here I have modified
function validate_login() and the
login.php codes:
modified
function validate_login() is:
function validate_login ( )
{
if ( document.login.user.value == "" )
{
$required.html("Please fill the user name.").dialog('open');
}
else if ( document.login.pass.value == "" )
{
$required.html("Please fill the password.").dialog('open');
}
else {
$.ajax({
type: "POST",
url: "login.php",
data: "user="+$("input[name='user']").val()+"&pass="+$("input[name='pass']").val(),
success: function(msg){
if(msg == 'success') {
window.location.href= "adminhome.php";
}
else {
$required.html(msg).dialog('open');
}
}
});
}
return false;
}
updated
login.php codes:
ob_start();
include "db.php";
$username=$_POST["user"];
$password=$_POST["pass"];
$username=strip_tags(stripslashes($username));
$password=strip_tags(stripslashes($password));
$mysqlqry="select username,password from admin_login where username='".$username."' and password='".$password."'";
$result = mysql_query($mysqlqry);
$count=mysql_affected_rows();
if(!$result)
{
echo("Can't execute the query.<br />");
echo("Error performing query: " . mysql_error() . "");
exit();
}
else
if($count==1)
{
setcookie("login","User",time()+2*3600);
echo("success");
exit();
}
else
{
echo "Invalid Username or Password.";
exit();
}
?>
Finally, I have removed the
action="login.php" from the form tag:
<form name="login" method="post" onsubmit="return validate_login( );"></form>