This snippet of code is giving me a problem in an application I'm creating, and when I run it gives me the error above.
$mysqli = new mysqli('localhost', 'username', 'password', 'database');
$ip = $_SERVER['REMOTE_ADDR'];
$userinfo = array();
$result = $mysqli->query('SELECT `ip` FROM `users` WHERE `ip` = ' .$ip. '');
if($mysqli->affected_rows == 0) {
return NULL;
}
else {
return $userinfo = $result->fetch_array;
}
Is there something wrong with my code; am I missing something? It would be nice to get an array of a user's information so it's easier to code different parts of my application. The full error message is:
Notice: Trying to get property of non-object in test.php on line 12