I am having trouble creating a login page. I am just beginning with PHP and MySQL so I'm going straight from the book here. I have set up a database that has the user John Doe in it with a password (that has been hashed). the username is jdoe and pass is doepass. However when I put those in the login forms and hit submit it just goes to a blank page. I'm pretty sure I've typed everything in correctly (and by pretty sure I mean double checked it 5 times) so, is there anything I need to do with Apache, like the mod_auth_dbm to get this to work or do in fact have a syntax error that is causing it not work.
Here is the code for the login page:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>15.7 User Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1>Login Form</h1>
<form method="post" action="listing15.8.php">
<p><strong>Username:</strong><br>
<input type="text" name="username"></p>
<p><strong>Password:</strong><br>
<input type="password" name="password"></p>
<p></p><input type="submit" name="submit" value="Login"></p></form>
</body>
</html>Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<?
if ((!$_POSTїusername]) || (!$_POSTїpassword])) {
header("Location: listing15.7.php");
exit;
}
$conn=mysql_connect("localhost", "****", "********")
or die(mysql_error());
mysql_select_db("sample_db", $conn) or die(mysql_error());
$sql = "select f_name, l_name from auth_users where username =
'$_POSTїusername]' AND password = password('$_POSTїpassword]')";
$result = mysql_query($sql, $conn) or die(mysql_error());
if (mysql_num_rows($result) == 1) {
$f_name = mysql_result($result, 0, 'f_name');
$l_name = mysql_result($result, 0, 'l_name');
setcookie("auth", "1", 0, "/", "mysite.com", 0);
$msg = "<p>$f_name $l_name is authorized!</p>";
$msg .="<p>Authorized Users' Menu:";
} else {
header("Location: listing15.7.php");
exit;
}
?>
<html>
<head>
<title>Listing 15.8 User Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<? print "$msg";
?>
</body>
</html>Any advice would be greatly appreciated. Thanks.
BigMC