OK I figured out how to check for duplicates using an unique index in MySQL.
try {
$this->query = 'INSERT INTO users (username, status, password, security, email, date_added) VALUES (:username, :status, :password, :security, :email, Now())';
$this->stmt = $pdo->prepare($this->query);
$this->result = $this->stmt->execute([':username' => $data['username'], ':status' => $status, ':password' => $this->pwd, ':security' => 'newuser', ':email' => $data['email']]);
} catch (Exception $e) {
die('Invalid Text');
//echo 'Caught exception: ', $e->getMessage(), "\n";
}
return true;
However, it works fine if there is no duplicate email address, but if there is a duplicate email it flags an exception error which is a good thing. Though obviously I don’t want to display an error message on a production server and I also don’t want a blank screen leaving the user confused. How, can get back to the registration screen if there is a duplicate? I hope I am making myself clear? I thought the whole purpose of a try-catch block was to do this sort of thing? Though no matter what I tried I just can’t figure it out and that is even after doing many internet searches. Thanks for the help in advance.