The users on the application are logged in by their e-mail. This e-mail is in a session. With this session I try to get more information of that user to print out there (sur)names and the avatar. When I do it in my navbar he's doing it all well but on the page itself it gives the following error: 'Fatal error: Cannot use object of type User as array'
What am i doing wrong?
PHP:
$user = new User();
$email = $_SESSION['email'];
$user->getUserInfoByEmail($email);
var_dump($user['avatar']);
FUNCTION:
public function getUserInfoByEmail($email)
{
$db = new Db();
$select = "SELECT * FROM tblusers WHERE email = '" . $_SESSION["email"] . "';";
$result = $db->conn->query($select);
return $data=$result->fetch_assoc();
}
It is because you are using the $user
object as an array (as the error message makes perfectly clear).
Change:
var_dump($user['avatar']);
To this:
var_dump($user->avatar);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With