简体   繁体   中英

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.

  1. In your update1.php , you included the connect.php , please check if you have the correct file name.

  2. Check if you have the correct password for the db config.

  3. 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.

To make a query, you use mysqli_query instead of mysqli_connect .

In update1.php :

//...
$result = mysqli_query( $connection, $query1 );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM