php - Giving Access denied for user 'SELECT * FROM users', but it's not a user
I have a problem that i can't fix by myself. The error is this:
mysqli_connect(): (HY000/1045): Access denied for user 'SELECT * FROM users'@'localhost' (using password: NO) in D:\xampp\htdocs\php\FUNCTIONS\UPDATE\update1.php on line 9
The fact is that SELECT * FROM users
is a query.
connection.php:
<?php
global $connection;
if ( isset( $_POST["submit"] ) ) {
$connection = mysqli_connect("localhost","root","","loginapp");
if ( !$connection ) {
die( "Query has failed!" . "<br/>" . mysqli_error( $connection ) );
}
}
?>
update1.php:
<?php
include 'D:\xampp\htdocs\php\FUNCTIONS\connect.php';
?>
<?php
$query1 = 'SELECT * FROM users';
$result = mysqli_connect( $connection, $query1 );
if ( !$result ) {
die( 'Query has failed!' . '<br/>' . mysqli_error( $connection ) );
}
?>
UPDATE:
I tried to change database and the error did go away. But the problem now is the connection variable. So i'm gonna delete the connect.php
and i will include the content of the file in every file that need to connect (but not create data ) to the database.
Answer
Solution:
In your
update1.php
, you included theconnect.php
, please check if you have the correct file name.Check if you have the correct password for the db config.
Looks like your query is correct so its probably a problem with your db config, check if the db password for the user -
root
is correct. You might have changed it.
Answer
Solution:
To make a query, you use mysqli_query
instead of mysqli_connect
.
In update1.php
:
//...
$result = mysqli_query( $connection, $query1 );
- More info here