I am trying to connect to a database using a login form. Currently there is one user in the database but when pressing submit the page just appears to refresh and is not redirected to the home page as it should. Here is my code:
<html>
<head><title>Login</title></head>
<body>
<?php
ob_start();
include('connect.php');
$handle = mysql_connect($hostname, $username, $password)or die("cannot connect");
$error = mysql_select_db($databasename,$handle);
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tablename WHERE UserName='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
session_register("username");
session_register("password");
header("Location: home.php");
}
else {
echo "Wrong Username or Password";
}
?>
<form action='LoginREAL.php'
method='POST' style='margin: .5in'>
<p><label for='user_name' style='font-weight: bold;
padding-bottom: 1em'>USER ID: </label>
<input type='text' name='username' id='username'
value='' /></p>
<p><label for='password' style= 'font-weight: bold'>Password: </label>
<input type='password' name='password' id='password'
value='' /></p>
<p><input type='submit' value='Login'> </p>
<input type='hidden' name='sent' value='yes'/>
<a href= "/home/jparry2/public_html/register.php">Register</a>
</form>
</body>
</html>