0

I'm trying to take out the game id from the database but I'm having trouble with it. And I do it like this:

if(!isset($_GET['round'])){
    $currentgame=$mysql->query('SELECT `value` FROM `info` WHERE `name`="current_game"')->fetch_assoc();
    $currentgame=(int)$currentgame['value'];

The error that comes up is

Fatal error: Call to a member function fetch_assoc() on boolean in C:\xampp\htdocs\index.php on line 85

I have no clue on what I might be doing wrong.

Deepak Rai
  • 2,163
  • 3
  • 21
  • 36
Nixdorn
  • 1
  • 1
  • you have an error in you query. Check for [mysqli_error](http://php.net/manual/en/mysqli.error.php)! – Jeff Mar 10 '17 at 02:58

1 Answers1

1

Without seeing all of your code, I'm assuming there's an error thrown by MySQL - possibly to do with the name="current_game"' section.

You should catch all errors when you're performing an action on a MySQL database. The error you're seeing at the moment is from MySQL returning boolean value FALSE.

Add something like this to your code:

if (!$currentgame) {
    throw new Exception("Database Error [{$mysql->query->errno}] {$mysql->query->error}");
}

This should help you work out what error is being returned.

Hayden R
  • 26
  • 3
  • Fatal error: Uncaught exception 'Exception' with message 'Database Error [] ' in C:\xampp\htdocs\index.php:85 Stack trace: #0 {main} thrown in C:\xampp\htdocs\index.php on line 85 This is the error that its showing me now – Nixdorn Mar 10 '17 at 03:06
  • Sorry, there was an error in my code - try the edited version – Hayden R Mar 10 '17 at 03:14
  • Sadly im still getting the same error even if i put it before, after, or in the middle of the code. Now i have no clue at what the reason for it might be – Nixdorn Mar 10 '17 at 03:34