Having a problem with the admin login in chapter 12. It doesn't redirect back to entry.php after putting in correct username and password. Instead I get an
"Internal Server Error:
The server encountered an internal error or misconfiguration and was unable to complete your request."
But when hitting the back button, I'll get to admin_area.php.
Why won't it redirect to entry.php?
Here's the code:
Code:
<?php
session_start();
include "conn.inc.php";
if (isset($_POST['submit'])) {
$query = "SELECT
username, password
FROM
admin
WHERE
username = '" . $_POST['username'] . "'
AND
password = '" . $_POST['password'] . "' ";
//the = (password(... wouldn't work, removed it
$result = mysql_query($query) or
die(mysql_error());
$row = mysql_fetch_array($result);
if (mysql_num_rows($result) == 1) {
$_SESSION['admin_logged'] = $_POST['username'];
$_SESSION['admin_password'] = $_POST['password'];
header("URL=" . $_POST['redirect'] . "");
}
else {
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<p>Invalid username, password, or both you schmuck!</p>
<form action="admin_login.php" method="post">
<input type="hidden" name="redirect"
value="<?php echo $_POST['redirect']; ?>" />
<p>
Username: <input type="text" name="username" />
</p>
<p>
Password: <input type="password" name="password" />
</p>
<input type="submit" name="submit" value="Login" />
</form>
</body>
</html>
<?php
}
}
else {
if(isset($_GET['redirect'])) {
$redirect = $_GET['redirect'];
}
else {
$redirect = "entry.php";
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<p>log in</p>
<form action="admin_login.php" method="post">
<input type="hidden" name="redirect"
value="<?php echo $redirect; ?>" />
<p>
Username: <input type="text" name="username" />
</p>
<p>
Password: <input type="password" name="password" />
</p>
<input type="submit" name="submit" value="Login" />
</form>
</body>
</html>
<?php
}
?>
Thanks,
James