PHP Login issues

Alles, was PHP betrifft, kann hier besprochen werden.

PHP Login issues

Postby deathnsmaldoses » 29. May 2009 23:48

This is my last place for help i hope someone will know what the hell is wrong with my code

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
  // Start the session

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" dir="ltr" lang="en" xml:lang="en">

   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
   <title>Read the whole file...</title>



    // 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...";

   // Check for minimum password length
   if (strlen($p)<5){
        echo "<h1>Access Denied</h1>";   
        echo "<p>Password is too short...";

    // Initialise variable

    // 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."'";   
   $num=mysql_numrows($result)or die("Error ".mysql_errno().": ".mysql_error()."\nQuery: $query");
   if ($num==1) $valid_user=true;
    // Make decision
    if ($valid_user==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..";




thanks in advance!
Posts: 1
Joined: 29. May 2009 23:43

Re: PHP Login issues

Postby Wiedmann » 30. May 2009 08:16

Code: Select all
$connection = mysql_connect("localhost","projectechelon","") or die(mysql_error());
mysql_select_db("projectechelon")or die(mysql_error());

"Access denied for user ''@'localhost' to database 'projectechelon'"

I guess there is no user "projectechelon" in your database.

And so you are connected as anonymous user, which don't have privileges for the database "projectechelon".
AF Moderator
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Return to PHP

Who is online

Users browsing this forum: No registered users and 9 guests