php - Trying to get property of non-object MySQLi result -


this question has answer here:

got bit of php code i'm struggling - had search around google etc. , tried mentioned, reason i'm having trouble solving it.

the problem is:

i have code querying database presence of particular user.

the code (it's method inside class)

<?php global $mysqli; // query specified database value $q = 'select id ' . $database . ' username = \'' . $username . '\''; $r = $mysqli->query($q); var_dump($r); if ($r->num_rows) {     // if row found username exists return false     return false; } ... ?> 

i've var dumped result of query ($r) , got this:

object(mysqli_result)#4 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> null ["num_rows"]=> int(1) ["type"]=> int(0) } 

this correct, there should 1 row above.

i error linking line saying if ($r->num_rows) {

notice: trying property of non-object in file on line line

but don't know why since object valid (as above) , should working fine. can tell seems going through alright, i'm wondering why there's error. i'm sure it's simple i'd appreciate help.

$sql = "select * table"; $result = $conn->query($sql);  if (!$result) {     trigger_error('invalid query: ' . $conn->error); } 

check error mysqli_error() function

probably query has faults.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -