How can one handle non-existent user errors in a PHP MySQL login system to prevent non-object error messages?
When handling non-existent user errors in a PHP MySQL login system, it is important to check if the query returned any results before trying to access properties of the result. This can prevent "non-object" error messages from occurring. One way to handle this is to use the `rowCount()` method to check if any rows were returned by the query before attempting to fetch the user data.
// Check if the query returned any results
if ($stmt->rowCount() > 0) {
// Fetch the user data
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// Proceed with login process
} else {
// Handle non-existent user error
echo "User not found";
}