Im tryign to setup code for a members only section but keep getting a error "Access denied for user ''@'localhost' to database 'projectechelon'"
the following is my code:
- Code: Select all
<?php
// Start the session
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Read the whole file...</title>
</head>
<body>
<?php
// Fetch username and password from form
$u = $_POST["field1"];
$p = $_POST["field2"];
// Trim username and password
$u = trim($u);
$p = trim($p);
// Check for minimum username length
if (strlen($u)<5){
echo "<h1>Access Denied</h1>";
echo "<p>Username is too short...";
session_destroy();
die();
}
// Check for minimum password length
if (strlen($p)<5){
echo "<h1>Access Denied</h1>";
echo "<p>Password is too short...";
session_destroy();
die();
}
// Initialise variable
$valid_user=FALSE;
// Encrypt password using sha1 algorithm
$p = sha1($p);
// Open Database
$connection = mysql_connect("localhost","projectechelon","") or die(mysql_error());
mysql_select_db("projectechelon")or die(mysql_error());
$query="SELECT * FROM member WHERE username='".$u."' AND password='".$p."'";
$result=mysql_query($query);
$num=mysql_numrows($result)or die("Error ".mysql_errno().": ".mysql_error()."\nQuery: $query");
mysql_close($con);
if ($num==1) $valid_user=true;
// Make decision
if ($valid_user==TRUE) {
$_SESSION['welcome']=TRUE;
echo "<h1> WELCOME! </h1>";
echo "<p>Please click <a href='members/'>here</a> for the members area...";
} else {
echo "<h1> Access Denied </h1>";
echo "You entered bad credentials fool..";
session_destroy();
die();
}
?>
</body>
</html>
thanks in advance!