Page not redirecting properly(php)
- by user225269
I want to do the login page this way so that I won't be having trouble posting the username
in the userpage. But everytime I try to access login.php. I get an error in firefox, that
the page is not redirecting properly. What do I do?
This works when I separate them into two. Into something like, login.php and verifylogin.php as the form action. But if I do it like this, I get redirection errors:
<?php
$host="localhost";
$username="root";
$password="nitoryolai123$%^";
$db_name="school";
$tbl_name="users";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$uname = mysql_real_escape_string($_POST['username']);
$pword = mysql_real_escape_string($_POST['password']);
$SQL = "SELECT * FROM users WHERE username = '$uname' AND password = '$pword'";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
if ($result) {
if ($num_rows > 0) {
session_start();
$_SESSION['login'] = "1";
header ("Location: userpage.php");
}
else {
session_start();
$_SESSION['login'] = "";
header ("Location: login.php");
}
}
else {
$errorMessage = "Error logging on";
}
?>
<tr>
<form name="form1" method="post" action="login.php">
<td>
<table>
<tr>
<td><strong><font size="2">Login User</strong></td>
</tr>
<tr>
<td width="30" height="35"><font size="2">Username:</td>
<td width="30"><input name="username" type="text" id="username" maxlength="17"></td>
</tr>
<tr>
<td width="30" height="35" ><font size="2">Password:</td>
<td width="30"><input name="password" type="password" id="password" maxlength="17"></td>
</tr>
<td><td align="right" width="30"><input type="submit" name="Submit" value="Submit" /></td> <td><input type="reset" name="Reset" value="Reset"></td></td>
</tr>
</form>
please help, thanks.