A registration form asks for username and e-mail address. After the data passes validation it's added to the accounts
table. It stores data such as username, password and e-mail address. If the username has already been taken the user will be notified and no data will be added to the table. It was seen as a security issue if the user was immediately notified that the e-mail address was already in the table. The suggested solution to this was to always send a verification e-mail and if the entered username already existed the e-mail would say "this e-mail address has already been used" (and no activation link would be given of course).
The problem is that as it works now, if the INSERT
query fails to insert the data into the table the message "Username taken" is shown. This may be wrong because the e-mail address is set to unique in the table so the query fails if the same e-mail address is entered. I can no longer send out a verification e-mail saying "this e-mail address has already been used" because there is no record in the table containing said e-mail address.
How can I redesign the system so it works?
I'm using MySQL and the table accounts
has the primary key username
unique key e-mail
and the attributes password
and activation
.
if(mysqli_stmt_execute($createAccount))
echo 'Username available!';
else
echo 'Username unavailable!';
In SQL is there some way to check to see why the query couldn't be inserted into the table? For example could it tell which attribute had a duplicate value?
Please let me know if my question is unclear.
Run a SELECT query first to identify duplicates. If no duplicates are found, then you can perform your INSERT.