I have a process_login page which gathers the form field data from the previous page. Through testing, i've ensured that the data IS coming across to this page, that the connection to the DB has been established, that the login data IS correct or incorrect.... YET... the damn thing doesnt redirect how i want it.
Here's my code:
Ideally, if the username/password is valid, Id like them to be redirected to start.php... otherwise... back to index.php.
The problem is, EVEN when the username/password IS correct... it wont go to start.php like it's supposed to.
I know I get a '1' when my un/pwd is correct.. and a '0' when it's not.
Can't seem to figure it out. Any Ideas?
<?
// Start a session
session_start();
$dblink = mysql_connect ("localhost", "user", "password")
or die ('I cannot connect to the database.');
if(mysql_select_db ("db", $dblink))
{
$dbStatus = "GOOD";
}
else
{
$dbStatus = "BAD";
}
$localun = $_POST['username'];
$localpw = $_POST['password'];
// Query DB
$Query = "select * from users where username = '$localun' and password = '$localpw'";
$dbResult = mysql_query($Query, $dblink);
// Test for number of rows
$numOfRows = mysql_num_rows($dbResult);
if($numOfRows == 0)
{
header("location:index.php");
exit;
}
elseif($numOfRows == 1)
{
// Add username to session variables
$_SESSION['username'] = $localun;
header("location:start.php");
exit;
}
else
{
header("location:index.php");
exit;
}
?>
<html>
<body>
<? print("$dbStatus <br>"); ?>
<? print("$localun"); ?>
<? print("$numOfRows <br>"); ?>
</body>
</html>