the below code does not login even though in the book i have it seems (Screenshots) to work fine
i have only included the relevant area of the code the rest just makes sure both login fields were entered
Code: Select all
if ($u && $p) {
require_once ('../mysql_connect.php');
$query = "SELECT username, first_name FROM users WHERE username='$u' AND password='$p'";
$result = @mysql_query ($query); // Run the query.
$row = mysql_fetch_array ($result, MYSQL_NUM);
if ($row) {
// Set the cookies & redirect.
setcookie ('first_name', $row[1]);
setcookie ('username', $row[0]);
header ("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/loggedin.php");
exit(); // Quit the script.
} else { // No record matched the query.
$message = '<p>The username and password entered do not match those on file.</p>';
}
mysql_close();
} else {
$message .= '<p>Please try again.</p>';
}i googled the error and found that it is fixed by adding an @ so
Code: Select all
$row = mysql_fetch_array ($result, MYSQL_NUM);reads as
Code: Select all
$row = @mysql_fetch_array ($result, MYSQL_NUM);i know there is a record in the data base i have viewed it with phpMyAdmin i have also tried with and without the PASSWORD('$p') to encrypt the password in the database