Hello I'm new to PHP and I am trying to make a simple login and register function for the user. Once user registers, his details will be added into the database so he can login. But now even though his username & pw are correct it does not login.
Here is my code:
<?php
if(!empty($_POST['username']) && !empty($_POST['password']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = md5(mysql_real_escape_string($_POST['password']));
$checklogin = mysql_query("SELECT * FROM admin WHERE Username = '".$username."' AND Password = '".$password."'");
if(mysql_num_rows($checklogin) == 1)
{
$row = mysql_fetch_array($checklogin);
$email = $row['Email_Address'];
$_SESSION['Username'] = $username;
$_SESSION['Email_Address'] = $email;
$_SESSION['LoggedIn'] = 1;
echo "<h1>Success</h1>";
echo "<p>We are now redirecting you to the member area.</p>";
echo "<meta http-equiv='refresh' content='=2;index2.php' />";
header("Location: Home.php");
}
else
{
echo "<h1>Error {$password}</h1>";
echo "<p>Sorry, your account could not be found. Please <a href=\"index2.php\">click here to try again</a>.</p>";
}
}
else
{?>
<h1>Member Login</h1>
<p>Please either login below, or <a href="register2.php">click here to register</a>.</p>
<form method="post" action="index2.php" name="loginform" id="loginform">
<fieldset>
<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
<input type="submit" name="login" id="login" value="Login" />
</fieldset>
</form>
<?php }?>
Any help is appreciated