ganjan
ganjan

Reputation: 7576

mysqli object how do I get the fields

$result = $conn->query("SELECT * FROM temp_users WHERE reg_code ='$passkey'");

This works:

if($result->num_rows == 1){

values from print_r($result);

mysqli_result Object ( [current_field] => 0 [field_count] => 11 [lengths] => [num_rows] => 1 [type] => 0 )

but $result->username where username is a field in the db shows up blank?

Upvotes: 1

Views: 3000

Answers (2)

Erik B
Erik B

Reputation: 42554

You need to use mysqli_fetch_array or similar.

Upvotes: 2

MartyIX
MartyIX

Reputation: 28648

Yes, because you need to fetch a row from the $result. It can be done via function: http://www.php.net/manual/en/mysqli-result.fetch-array.php and a few more - check PHP manual.

From manual:

/* associative array */
$row = $result->fetch_array(MYSQLI_ASSOC);
echo $row["username"];

Upvotes: 2

Related Questions