Home>
Question content

When I tried to move the new login screen on the rental server with php, the following error occurred. By the way, it moved in the local environment. (Use XAMPP)
* User name and host name have been changed in local environment and rental server
I want to know what is the problem and this error is occurring.

Error message
SQLSTATE [28000] [1045] Access denied for user 'soumen_xxxx' @ 'localhost' (using password: YES)
Applicable source code

I will partially lie down.

// Session start
session_start ();
$db ['host'] = "mysql1.php.starfree.ne.jp";// DB server URL
$db ['user'] = "soumen_xxxx";// username
$db ['pass'] = "xxxx";// username password
$db ['dbname'] = "soumen_xxxx";// database name
// Initialize error message
$errorMessage = "";
// If the login button is pressed
if (isset ($_ POST ["login"])) {
    // 1. User ID input check
    if (empty ($_ POST ["userid"])) {// empty is empty
        $errorMessage = 'User ID is not entered. ';
    } else if (empty ($_ POST ["password"])) {
        $errorMessage = 'No password entered. ';
    }
    if (! empty ($_ POST ["userid"])&&! empty ($_ POST ["password"])) {
        // Store the entered user ID
        $userid = $_POST ["userid"];
        // 2. Authenticate if user ID and password are entered
        $dsn = sprintf ('mysql: host =% s;dbname =% s;charset = utf8', $db ['host'], $db ['dbname']);
        // 3. Error handling
        try {
            $pdo = new PDO ($dsn, $db ['user'], $db ['pass'], array (PDO :: ATTR_ERRMODE =>PDO :: ERRMODE_EXCEPTION));
            $stmt = $pdo->prepare ('SELECT * FROM userData WHERE name =?');
            $stmt->execute (array ($userid));
            $password = $_POST ["password"];
            if ($row = $stmt->fetch (PDO :: FETCH_ASSOC)) {
                if (password_verify ($password, $row ['password'])) {
                    session_regenerate_id (true);
                    // Get the username with the entered ID
                    $id = $row ['id'];
                    $sql = "SELECT * FROM userData WHERE id = $id";// Get the user name from the entered ID
                    $stmt = $pdo->query ($sql);
                    foreach ($stmt as $row) {
                        $row ['name'];// username
                    }
                    $_SESSION ["NAME"] = $row ['name'];
                    header ("Location: Main.php");// Go to main screen
                    exit ();// end processing
                } else {
                    // authentication failure
                    $errorMessage = 'The user ID or password is incorrect. ';
                }
            } else {
                // 4. If authentication is successful, issue a new session ID
                // no corresponding data
                $errorMessage = 'The user ID or password is incorrect. ';
            }
        } catch (PDOException $e) {
            $errorMessage = 'database error';
            // $errorMessage = $sql;
            // $e->getMessage () can be used to view error details (displayed only during debugging)
            // echo $e->getMessage ();
        }
    }
}

Host names, user names, and database names were those listed on the rental server.
The same result was obtained even if the password was changed.

Supplemental information (FW/tool version etc.)

The rental server uses Star Free.
MySQL5.7 is used.

  • Answer # 1

      

    Host names, user names, and database names were those listed on the rental server.
      The same result was obtained even if the password was changed.

    I mean ... I still write it

    $db ['host'] = "mysql1.php.starfree.ne.jp";// DB server URL
    $db ['user'] = "soumen_xxxx";// username
    $db ['pass'] = "xxxx";// username password
    $db ['dbname'] = "soumen_xxxx";// database name


    I think one of these four should be wrong.
    I think it's probably a username or password.

    Please try logging in with phpMyAdmin for now.
    If it still fails, it will be confirmed that it is not a problem of the program.