1
I made a code to check if the user and email are already existing, but when the user exists it returns the following error:
Fatal error: Fatal error: Cannot use Object of type stdClass as array
$query_check_user_name = $this->db->prepare('SELECT username, mail FROM users WHERE username= :user_name OR
mail = :user_email');
$query_check_user_name->bindValue(':user_name', $user_name, PDO::PARAM_STR);
$query_check_user_name->bindValue(':user_email', $user_email, PDO::PARAM_STR);
$query_check_user_name->execute();
$result = $query_check_user_name->fetchAll();
if (count($result) > 0) {
for ($i = 0; $i < count($result); $i++) {
$this->errors[] = ($result[$i]['user_name'] == $user_name) ? MESSAGE_USERNAME_EXISTS : MESSAGE_EMAIL_ALREADY_EXISTS;
}
} else {
}
I answered in the can, but forgot the classic question: "Which line did this error occur"?
– Wallace Maxters
Another tip: Don’t use the
for
to iterate witharrays
, especially with thatcount($result)
being called every check for :)– Wallace Maxters