August 19th, 2018, 10:13 AM
-
Notice: Trying to get property of non-object
Can anyone help me with this:
I'm returning
Notice: Trying to get property of non-object in....
Notice: Trying to get property of non-object in....
Notice: Trying to get property of non-object in....
Number of rows: 1
So the result set is not NULL
PHP Code:
$result = $connection->query("SELECT * FROM $table_name WHERE username = '$user' and password = password('$pass')");
$rows = mysqli_num_rows($result);
if ($rows) {
while ($row = mysqli_fetch_array($result))
{
$_SESSION['first_name'] = $row -> firstname;
$_SESSION['last_name'] = $row -> lastname;
$_SESSION['user_name'] = $row -> username;
}
}
echo "Number of rows: $result->num_rows";
What does the notice mean and why am I getting it?
Tks
August 19th, 2018, 10:30 AM
-
$row is not an object in this context, it is an associative array and numeric array.
PHP Code:
$_SESSION['first_name']=$row['firstname'];
or
PHP Code:
$_SESSION['first_name']=$row[0];
You can also specify only one or the other with a 2nd parameter to the fetch method (MYSQLI_NUM for numeric or MYSQLI_ASSOC for associative).
Last edited by gw1500se; August 19th, 2018 at 10:33 AM.
There are 10 kinds of people in the world. Those that understand binary and those that don't.
August 19th, 2018, 11:19 AM
-
Yes I just twigged it's an array - thanks very much for the reply. I like the binary thing.
August 19th, 2018, 12:10 PM
-
Please don't lock your threads once you get an answer. People may have something more to add.