I have a class that inserts the user from a registration form into a database. I am inserting 4 things: username, password, salt and an email. I am using errno 1062 to check for duplicate entries. But I need to check for specific duplicate entries. For example I have this logic that checks for errno 1062 but it's really not specific to the username being checked, it's just checking for an errno and assuming it's the username that's duplicated.
if ($stmt->affected_rows == 1) {
$this->success = "$this->username has registered. You can now log in.";
} elseif ($stmt->errno == 1062) {
$this->errors[] = "$this->username is already in use. Please chose another.";
} else {
$this->errors[] = 'Sorry, there was an issue with the database.';
}
My question is, how could I use errno 1062 to check for both username, email or both? Seems like errno 1062 just checks for ANY duplicate entries.