0

I'm getting this error in my code, the code is posted below as well. Fatal error: Call to a member function fetch_assoc() on boolean in C:\htdocs\www\ourgames\game\admin\functions\function.php on line 41

function getUsers_value(){
    global $conn;

    $user_id = $_SESSION['user_id'];

    $sql = "SELECT id, username, password, email FROM user";
    $results = $conn->query($sql);
    $row = $results->fetch_assoc();

    return $row['id'];
    return $row['username'];
    return $row['password'];
    return $row['email'];
}

this is my connect_game_db.php

$servername = "127.0.0.1";
$username = "root";
$password = "password";
$dbname = "game";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
?>
SimmeD
  • 179
  • 13

1 Answers1

0

This suggests that you have an error in your SQL as mysqli->query() returns FALSE on error - see http://php.net/manual/en/mysqli.query.php

I would suggest var_dump($results); to have a look at what's going on and if it's false call $mysqli->error to see the exact error.

kdvy
  • 404
  • 2
  • 9