I have been utilizing this forum to take help in creating my first PHP website. I have most of the things up and running, but am facing an issue with my login. If a new user signs up and login to the website, it works perfectly fine, but if I open the login database even once or if I view the list of users in the admin panel, all the previous user login fails and no one can login with those credentials again even when they are still present in the database. Any help? Below is my login form code:
<?php
session_start();
?>
<!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">
<html>
<head>
</head>
<body>
<table border="1" width="100%">
<form action="user.php" method="post">
<tr>
<td><label for="u_name">Your Email-id:</label></td>
<td><input type="text"name="u_name" id="u_name" placeholder="Enter email-id" required="required"/></td>
</tr>
<tr>
<td><label for="u_password">Password:</label></td>
<td><input type="password" name="u_password" id="u_password" placeholder="Enter password" required="required"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="sub" value="login"/></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['sub']))
{
$u_name=$_POST['u_name'];
$u_password=$_POST['u_password'];
include ("connection.php");
$w="select * from signup";
$b=mysql_query($w) or die(mysql_error()."in query $w");
while($row=mysql_fetch_array($b))
{
$a=$row['email_id'];
$u=$row['password'];
}
if ($u_name==$a && $u_password==$u)
{
$_SESSION['loggedin']=true;
$_SESSION['user_email']=$_POST['u_name'];
$_SESSION['user_pass']=$_POST['u_password'];
echo '<meta http-equiv="refresh" content="0; url=homepage.php">';
}
else
{
echo "Your username or password is incorrect.Please try again";
}
}
?>