Access is denied for the username '@' localhost '(using password: YES) in C: \ webdev \ wamp \ www \ membershipSite \ classes \ Mysql.php on line 9

I'm new to all of this, but I know a decent amount of HTML / CSS. I want to create a login server, and I got most of the code from the video. If someone can help me and explain in detail, so I can understand that it will be very appreciated. If you need any other material, I will gladly publish it.

<?php

require_once 'includes/constants.php';

class Mysql {
private $conn;

function _construct() {
    $this->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or die('There was a problem connecting to the database.');
}

function verify_Username_and_Pass($un, $pwd) {

    $query = "SELECT *
            FROM users
            WHERE username = ? AND password = ?
            LIMIT 1";

    if($stmt = $this->conn->prepare($query)) {
        $stmt->bind_param('ss', $un, $pwd);
        $stmt->execute();

        if($stmt->fetch()) {
            $stmt->close();
            return true;
        }
    }

}
}
+5
source share
2 answers

You need to grant permissions for the @host user in mysql. The grant command looks like

grant all privileges on YOURDB.* to
'YOURUSER'@'localhost' identified by 'YOURPASSWORD';
+9
source

, , , ,

,

        <?php

        session_start();

        $db_host="host";
        $db_user="user";
        $db_pass="mypassword";
        $db_name="dbname";
        $db_table="tblname";

        mysql_connect($db_host, $db_user, $db_pass) or die(mysql_error());
        mysql_select_db($db_name) or die(mysql_error());

, , $, script, , ,

        $db_pass="mypass$word";
+3

All Articles