Hi,

Set up DB, sql file. Looks ok.

Get

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a2108135'@'localhost' (using password: NO) in /home/a2108135/public_html/connect.php on line 27

Line 26-27

$dblink=MYSQL_CONNECT($MySqlHostname, $MySqlUsername, $MySqlPassword) or die("Could not connect to database");
    @mysql_select_db("$MySqlDatabase") or die( "Could not select database");

Any help, thanks!!!

L-D

Dani AI

Generated

Two separate problems are showing up and they’re easy to fix once you line them up.

First, the parse error (the stray character before the code) must be removed — that stops PHP from running and can prevent your connection variables from being set. Second, the “Access denied … (using password: NO)” means the connection call received an empty password value. As pointed out, that usually means wrong or missing credentials; as suggested, also check which host the DB user is allowed to connect from.

Concrete steps to resolve:

  • Remove any stray characters (the single-letter stray line) so the file parses.
  • Make variable names consistent and case-correct. PHP variables are case-sensitive; if you set one name but call a differently-cased name, the connection sees an empty value. Define your DB host/user/pass/name once and use those exact variables at the connection point.
  • Stop emulating register_globals; use explicit variables and superglobals ($_POST, $_GET, etc.) instead — emulation is insecure and unnecessary.
  • Temporarily verify values without printing passwords to the browser (for example, log checks that show whether the password variable is empty).

Modernize and secure:

  • Move credentials outside the webroot or protect the config file and set restrictive file permissions. If credentials were posted publicly, rotate the password.
  • Prefer PDO or mysqli over the old mysql extension (removed from PHP 7+) for better error handling and security. Example PDO pattern:
<?php
$dsn = 'mysql:host=HOST;dbname=DBNAME;charset=utf8mb4';
$options = [PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION];
try {
    $pdo = new PDO($dsn, 'DBUSER', 'DBPASS', $options);
} catch (PDOException $e) {
    error_log('DB connect error: '.$e->getMessage());
    die('Could not connect to database.');
}
?>

If problems persist after these fixes, confirm the MySQL user actually has privileges for the specified host (localhost vs. a remote host) and check MySQL error logs for the precise failure.

Recommended Answers

All 3 Replies

Make sure your username is correct, since the warning says "Access denied"

Make sure that the username has access from the IP from where you want to connect to the server.

Is localhost your server or a remote one ?

Hi and thanks!!

Make sure your username is correct, since the warning says "Access denied"
seems to be ok.

It's localhost.

Make sure that username has access from the IP
I'm cluless.

Well, now I get:
Parse error: syntax error, unexpected T_IF in /home/adven735/public_html/connect.php on line 14

(connect.php note line 14)

<?php

$mysql_host = "localhost";
$mysql_database = "adven735_myblackcat";
$mysql_user = "adven735_mycat";
$mysql_password = "5d(KXU3g,.}H";

x

// do not edit below this line!!     
///////////////////////////////////////////////////////////////////////

    /// Register Gloab Emulation
Line 14>>>   if (!ini_get('register_globals')) {
        $superglobals = array($_SERVER, $_ENV,
                $_FILES, $_COOKIE, $_POST, $_GET);
        if (isset($_SESSION)) {
            array_unshift($superglobals, $_SESSION);
        }
        foreach ($superglobals as $superglobal) {
            extract($superglobal, EXTR_SKIP);
        }
    }



    $dblink=MYSQL_CONNECT($MySqlHostname, $MySqlUsername, $MySqlPassword) or die("Could not connect to database");
    @mysql_select_db("$MySqlDatabase") or die( "Could not select database");


?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.