Access denied for user 'root'@'localhost' (using password: YES)

Discussion in 'PHP' started by jawednazarali, Jul 29, 2007.

  1. #1
    Hello,

    When I am trying to connect to mysql database from php script I am getting following error.

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in D:\tools\Apache2\htdocs\saz\admin\index.php on line 27

    /* PHP code start*/
    //Set database connection
    $server = mysql_connect($host, $username, $password) or die("Can't find the Database Server");
    // Select the database now:
    $connection = mysql_select_db($database, $server) or die("Invalid Database schema");
    $sql = "SELECT * FROM users WHERE userID = '$userID' AND password = '$password'";
    $results = mysql_query($sql);
    if ($user = mysql_fetch_array($results))
    {
    echo $user['name'];
    }
    mysql_close($server);
    /* PHP code ended */
    Code (markup):

    All the required information provided to database server are correct. I using following environment:
    apache 2.0.53,
    mysql 4.1.22-community-nt,
    PHP 5.1.1

    Please guide me how to fix the issue.

    Thank you,
     
    jawednazarali, Jul 29, 2007 IP
  2. 0xpf

    0xpf Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try connecting to mysql from command line.

    <Path>\mysql.exe -u root -p <password>

    If that works, nothing wrong with setup, it could be something in the code.

    If that does not work, login to mysql and run this command:
    SET PASSWORD FOR 'root'@'host_name' = PASSWORD('eagle');
    where eagle is the password.
    Details here: http://dev.mysql.com/doc/refman/5.0/en/access-denied.html

    Try the command line version again and make sure it works.
     
    0xpf, Jul 29, 2007 IP
    subseo likes this.
  3. jawednazarali

    jawednazarali Guest

    Messages:
    254
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I just found out that I am using two same variables on the page, thats causing the problem.

    any ways thanks for replying.
     
    jawednazarali, Jul 29, 2007 IP