php - mySQL Access Denied Error After New User Created -


i made projects using mysql , there no problem. today friend show me how create user in mysql :

create database cc; use cc create user 'testing'@'localhost' identified 'pass'; grant on cc.* 'testing'@'localhost'; 

now tried use project got following error :

connection failed: access denied user ''@'localhost' database 'login' 

i deleted created user :

drop user 'testing'@'localhost'; 

i managed delete user, checked user :

select user mysql.user; 

testing account gone have 3 root accounts, didn't understand why. since deleted "testing" account, tried project again , got same error. why can't use default 'root' account anymore?

edit :

error part of php code :

$servername = "localhost"; $username = "root"; $password = ""; $dbname = "login";   // error in following line $conn = mysqli_connect ( $servername, $username, $password, $dbname ); 

i tried :

grant on login.* 'root'@'localhost';  show grants;  

result :

grant privileges on *.* 'root'@'localhost' grant option grant privileges on login.* 'root'@'localhost' 

it seems 'root' has access everything. why getting error?

edit 2:

<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "login"; $username = $_post['username']; $pass = $_post['password'];  // create connection $conn = mysqli_connect ( $servername, $username, $password, $dbname ); // check connection if (! $conn) {     die ( "connection failed: " . mysqli_connect_error () ); } 

your on riding set $username variable $_post['username'] data appears empty. mysqli_connect attempts connect database blank username.

to correct this, rename $username variable else doesn't conflict.

example:

<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "login"; $username_post = $_post['username']; $pass = $_post['password'];  // create connection $conn = mysqli_connect ( $servername, $username, $password, $dbname ); // check connection if (! $conn) {      die ( "connection failed: " . mysqli_connect_error () );  } 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -