Reputation: 2417
I have a user class to get all user data, I tried to show a particular user's email but have error with Fatal error: Cannot use object of type User as array in C:\...
, please advise.
class:
class User{
public function get_user_info($user_id, $mysqli){
if(empty($user_id)) {
return null;
}
$sql = $mysqli->query("SELECT * FROM `users` WHERE user_id='".$user_id."' LIMIT 1");
if($sql->num_rows > 0){
$row = $sql->fetch_array(MYSQLI_BOTH);
return $row;
}
return null;
}
}
call email:
include('classes/user.php');
$user = new User;
$user->get_user_info($user_id, $mysqli);
echo 'email: '.$user['user_email'];
Upvotes: 0
Views: 263
Reputation: 3933
$mysqli
is never defined in your code.
You cannot use something that was not defined.
Upvotes: 3