1

Get an error that won't allow me to load my index page. Weird cause my friend has the same exact code and it works.

error: Notice: Trying to get property of non-object in C:\xampp\htdocs\index.php on line 102

Notice: Trying to get property of non-object in C:\xampp\htdocs\index.php on line 107

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

Code:

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

//GAME INFO ARRAY AND PLAYERS COUNT
$gameinfo=$mysql->query('SELECT * FROM `games` WHERE `id`="'.$currentgame.'"')->fetch_assoc();

$players=$mysql->query('SELECT DISTINCT `userid` FROM `'.$prf.$currentgame.'`');
$playersnum=$players->num_rows;

// ITEMS NUMBER AND GAME TOTAL VALUE

$items=$mysql->query('SELECT * FROM `'.$prf.$currentgame.'` ORDER BY `value` DESC');
$itemsnum=$items->num_rows;

$originalgamevalue=$mysql->query('SELECT SUM(`value`) AS `total` FROM `'.$prf.$currentgame.'`')->fetch_assoc();
$originalgamevalue=(float)$originalgamevalue['total'];
$gamevalue=myround($originalgamevalue);

// TIMELEFT IN GAME
if($gameinfo['starttime'] == 2147483647){
    $timeleft=$site['gametime'];
}else{
    $timeleft = $gameinfo['starttime']+($site['gametime']-time());
    $timeleft=$timeleft-2; //compensate for page loading times

    if($timeleft<0){
        $timeleft=0;
    }
}

I am making a connection to the database, as on other pages it grabs stuff from the database and the error doesn't say unable to connect to database.

Kara
  • 6,115
  • 16
  • 50
  • 57
  • It's not clear what $mysql is. It's some sort of abstraction layer. The problem appears to be in your Mysql abstraction layer, but without seeing the code, it's difficult to debug. – Halfstop Feb 24 '16 at 22:27
  • Better to check by executing **SELECT** query first and then check the returned rows by this . If the returned rows will be more than 0 then you can use **fetch_assoc()** – Deepak Dixit Feb 25 '16 at 20:30

0 Answers0