This is my php code for a login form. Please help i check my code 4-5 time but did not reach out the problem here. The problem is that my if block is executed successfully but else part is not working. I don't what is happening here. Please tell me why my code is not executed properly.
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form method="post">
<table>
<tr><td>User<input type="text" name="fuser"/></td></tr>
<tr><td>Password<input type="password" name="fpassword"/></td></tr>
<tr><td><a href="#">Lost Password</a> <a href="form.php">Create new Account</a></td></tr>
<tr><td><input type="submit" name="fsubmit" value="Login"/></td></tr>
</table>
</form>
</body>
</html>
PHP
<?php
if(isset($_POST['fsubmit']))
{
$hostname="localhost";
$username="root";
$dbpassword="";
$db="php";
$user=$_POST['fuser'];
$password=$_POST['fpassword'];
mysql_connect($hostname, $username, $dbpassword) or die("Server not Found, May be connection lost somewhere.");
mysql_select_db($db) or die("Error Established, Database Not Connected.");
$query="select * from register where user='$user' and password='$password'";
$rs=mysql_query($query) or die("Query not Executed, Some Fault.");
while($r=mysql_fetch_assoc($rs))
{
if($user==$r['user'] && $password==$r['password'])
{
echo "<script>alert('You Are Login Successfully.')</script>";
echo "Please Wait We Moving Now, Don't Press F5 or Refresh Button";
header("Refresh:3; URL=dashboard.php");
}
else
{
echo "<script>alert('Sorry Try Agian or Register First.')</script>";
echo "Please Wait We Moving Now, Don't Press F5 or Refresh Button";
header("Refresh:1; URL=form.php");
}
}
}
?>