Put simple, I’m populating a user object based on a username entered
`$thisUser = $User->getByUsernameOrEmail($_POST[‘username’]);
this returns a user object. if nothing is found by the username all my properties are still empty.
how can i check if one has been found?
user Class
private int $userId;
private string $userFirstName;
private string $userLastName;
private string $gender;
private string $dob;
private string $email;
private int $userLevel;
private $dbh;
public function __construct(database $database){
$this->dbh = $database;
}
public function getByUsernameOrEmail(string $username){
$sql = “SELECT * FROM `users` WHERE `userName` = ? OR `email` = ? LIMIT 1”;
$stmt = $this->dbh->prepare($sql);
$stmt->bind_param(‘ss’, $username, $username);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if ($result->num_rows > 0){
$this->userId = $row[‘userId’];
$this->userName = $row[‘userName’];
$this->userFirstName = $row[‘firstName’];
$this->userLastName = $row[‘lastName’];
$this->gender = $row[‘gender’];
$this->dob = $row[‘dob’];
$this->email = $row[’email’];
$this->userLevel = $row[‘accessLevel’];
}
return $this;
}