
January 26th, 2004, 01:26 AM
|
|
Junior Member
|
|
Join Date: Jan 2004
Posts: 2
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Weird Header("Location function
This is really pissing me off...
I use a login form to log the user in and if the username and password are correct than the user gets redirected to the 'account.php' page. But the stupid script keeps redirecting back to the <form action=".." method="post"> url which is loginp.php
here is the code for login.php:
PHP Code:
<form action="loginp.php" method="post">
<tr>
<td width="361" style="font-weight: bold; color: black; border-style: none" height="31">
<p align="right"><b>Username:</b></p>
</td><td width="310" height="31">
<p><input type="text" name="username" size="20"> <sup>
<font face="Tahoma">(Case Sensitive)</font></sup></p>
</td></tr>
<tr>
<td width="361" style="font-weight: bold; color: black; border-style: none" height="20">
<p align="right"><b>Password:</b></p>
</td><td width="310" height="20">
<input type="password" name="password" size="20"> <sup> <font face="Tahoma">(Case Sensitive)</font></sup>
</td></tr>
</table>
<p align="center"><input type="submit" value="Log-In" name="B1">
<input type="button" value="Cancel" name="B2" onClick="parent.location.href='default.php'">
</form>
and here is the PHP code for loginp.php:
PHP Code:
<?
if (!isset($_POST['username']) | !isset($_POST['password'])){
//do nothing
} else {
//connect to database
include 'connect.php';
$sql = mysql_query("SELECT MemberID, UserName, Password FROM members WHERE BINARY UserName = '".$_POST['username']."'") or die("Query failed : " . mysql_error());
$fetch_em = mysql_fetch_array($sql);
$numrows = mysql_num_rows($sql);
if($numrows != "0" & $_POST['password'] == $fetch_em["Password"]) {
//echo "login successful";
$_SESSION['memid'] = $fetch_em["MemberID"];
$_SESSION['username'] = $fetch_em["UserName"];
Header("Location: account.php");
} else {
echo "<b><font color=red>Login Unsuccessful</font></b>";
}
/* Free resultset */
mysql_free_result($sql);
/* Closing connection */
mysql_close($link);
}
?>
the loginp.php code actually woks but for some stupid reason it redirects to "loginp.php" page rather than "account.php" page.
can anyone please explain why it is doing this?
Thanks.
|