cant connect to database!!!!!!!!!!!!!

Hello i made a live website and when you try and login it gives me this error

Warning: mysqli_connect(): (HY000/1045): Access denied for user ‘root’@‘localhost’ (using password: NO) in C:\wamp\www\index.php on line 3

here is my code if you need it
[php]

<?php // Connecting $con = mysqli_connect('localhost','root','','prankvsprank'); // Testing Connection if (mysqli_connect_errno()){ echo"Failed to connect" . mysqli_connect_error(); } // Declairing Variables $Username = @$_POST['Username']; $Password = @$_POST['Password']; $Submit = @$_POST['submit']; // If Statements if($Submit==TRUE){ if($Username==TRUE){ if($Password==TRUE){ $insert = mysqli_query($con, "INSERT INTO prankvsprank VALUES('','$Username','$Password')")or die("Couldnt insert data into database prankvsprank"); }else echo" Enter a password to continue"; }else echo"Enter a username to continue"; } ?> <?php //Login Script $con = mysqli_connect('localhost', 'root', '', 'prankvsprank'); if (mysqli_connect_errno()) { echo"Erry While Trying To Connect To Database" . mysqli_connect_error(); } $Username = @$_POST['lUsername']; $Password = @$_POST['lPassword']; $submit = @$_POST['lsubmit']; $logout = @$_POST['logout']; if ($submit==TRUE) { if ($Password==TRUE) { if ($Username==TRUE) { $li = "SELECT * FROM prankvsprank WHERE username = '$Username' AND password = '$Password' LIMIT 1"; $res = mysqli_query($con, $li); if (mysqli_num_rows($res) == 1) { session_start(); echo '
Hello, <?php echo "$lUsername"?>
';

if ($logout==TRUE) {
session_destroy();
}

        }
    }
}

}
?>

Register body{background-color:black;}.registerform{position:absolute;top:20%;left:5%;}.loginform{position:absolute;top:40%;left:5%;}.box1{position:absolute;top:15%;left:25%;width:50%;height:100%;background-color:#F0FFFF;border-radius:15%;} .line_1{width:7%;color:#F0FFFF;position:absolute;top:37%;left:1%;}.line_2{width:7%;color:#F0FFFF;position:absolute;top:37%;left:10%;}.OR{position:absolute;top:36.7%;left:8.5%;}.title1{position:absolute;top:3%;left:33%;}.introtitle{position: absolute;top:18%;left:85%;}.introvid{position:absolute;top:25%;left:78%;}.hellouser{position:absolute;top:10%;left:30%;}.logoutbutton{position:absolute;top:36.6%;left:18%;} Register
Username:
Password:

or
Login
Username:
Password:
PrankvsPrank
Intro

[/php]

The problem is not with PHP it is your server. There must have been a password set for root which you are not using. Either create another user name and password for the database and use that , or add the password for your root user to your code, or remove the root password from the database

i changed the pass and changed it in the config it still gave the same error

Try adding a new user and password to the db. The error message you showed before shows that you are connecting to the database, but your login credentials are incorrect

i made a new user and password then it gave me this error the pass is right tho

Warning: mysqli_connect(): (28000/1045): Access denied for user ‘812d’@‘localhost’ (using password: YES) in /home/u297061460/public_html/index.php on line 3

it works fine if i do it from my localhost but the hosted one still gives that error

Then it’s the hosted server that you need to do appropriately with the password. Do you want of the above mentioned things on the hosted server.

Keep in mind, the mysql password is not necessarily the same as the server user password. Depending on the hosted server config, you may not be able to use local host. You may have to use the ip address or some other host name. Contact your hosting provider

Sponsor our Newsletter | Privacy Policy | Terms of Service