I have created a blog and have added a login box which prompts the user for login and id before posting- The username and password have been stored in the database, however when i enter the username and pasword it does not seem to compare the values entered with anything. It jus keeps giving the prompt box to enter details. But if i click cancel, then it tels me the incorrect credentials ave been entered i have tried many ways to solve this problem but cant seem to see where i am gng wrong- the code is below, and some of the code was already provided, Function to authenticate was given -
And this code is called when the user tries to enter a new posting option from the index page, so before the addentry page displays, the user must login- if any more code is required, let me know-
Thanks in advance- This is my first ever php program and it was all going ok untill this. thanks
[PHP] // Function to authenticate
function authenticated($username, $password) {
// Connect to Database Server
$Hostname = "2006";
$Username = "anon";
$Password = "anonpassword";
//open the connection
$conn = mysql_connect($Hostname,$Username, $Password);
// Choose database
mysql_select_db("anon", $conn);
// Build SQL query to:
// find row in database with
// matching $username and $password
// Execute query
$query = mysql_query( "SELECT * FROM blog_user WHERE name == '".$username."' AND password == '".$password."';", $conn);
// IF number of rows is equal to one
// return true
if ($query == 1)
{
return true;
}
// ELSE return false
else
{
return false;
}
}
// Assign username and password from $_SERVER global array
$username = $_SERVER["PHP_AUTH_USER"];
$password = $_SERVER["PHP_AUTH_PW"];
// Decide whether to show blog entry form, or deny access
if (!authenticated($username, $password)) {
// Credentials either:
// not sent (1st time script is called)
// credentials do not match database
// Display HTTP Authentication Challenge
header("WWW-Authenticate: Basic Realm=\"Blog Station\"");
header("HTTP/1.1 401 Unauthorised");
// Print a message about incorrect credentials
echo " Incorrect credentials provided, please try again";
echo ("<a href = \"index.php\"> Re-Enter");
exit;
}
else {
// Correct credentials provided, print the blog entry form
//using the echo as a check
echo " Authorised";
}[/PHP]