My problem comes in it is not recognizing name or password. I have two names placed in the database table for membership that I use for testing.
The username and password entered do not match those on file.
if (isset($_POST['submit'])) { // Check if the form has been submitted.
require_once ('incl/mysql_connect.php'); // Connect to the database.
if (empty($_POST['name'])) { // Validate the username.
$u = FALSE;
echo '<p><font color="red">You forgot to enter your username!</font></p>';
} else {
$u = escape_data($_POST['name']);
}
if (empty($_POST['password'])) { // Validate the password.
$p = FALSE;
echo '<p><font color="red">You forgot to enter your password!</font></p>';
} else {
$p = escape_data($_POST['password']);
}
if ($u && $p) { // If everything's OK.
// Query the database.
$query = "SELECT member_id, name FROM membership WHERE name='$u' AND password=PASSWORD('$p')";
echo mysql_error();
$result = @mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row) { // A match was made.
// Start the session, register the values & redirect.
$_SESSION['name'] = $row[1];
$_SESSION['member_id'] = $row[0];
ob_end_clean(); // Delete the buffer.
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
exit();
} else { // No match was made.
echo '<p><font color="red">The username and password entered do not match those on file.</font></p>';
}
mysql_close(); // Close the database connection.
} else { // If everything wasn't OK.
echo '<p><font color="red">Please try again.</font></p>';
}
} // End of SUBMIT conditional.
<table width=100% border=0 cellspacing=1 cellpadding=1 name=menu>
<tr><td class=menuheader align=center>Login</td></tr>
<tr><td class=menuBody>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input class=title name="name" type="text" id="name" style="width: 100px;" maxlength="30" value="">
<strong>Member Name</strong>
<input class=title style="width: 100px;" type="password" name="password" size="20" maxlength="20" /><br/><strong>Password</strong>
<br/><input type="submit" name="submit" value="Login">
</form></td></tr>
</table>
I dont know if this could be the problem but on my footer.html I have the following:
if (isset($_SESSION['member_id'])) {
echo "<b>Member</b>: {$_SESSION['name']}<br/>
<b>Last Login</b>:
<b>Total Posts</b>:";
} else {
include('login.php');
}