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
<?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!
deathnsmaldoses
 
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".
Wiedmann
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 1 guest