I recently updated a "username" column in a MySQL database with a "UNIQUE" constraint.
Someone had suggested to me that this would be a quick and easy way to prevent the entering and storing of duplicate usernames in the database. It was easy enough to do, .. and it DOES prevent the duplicates. However, it's not very elegant, and gives no message or indication to the user that a duplicate record was encountered. All that happens is that the page refreshes itself.
I need to update my "ADD USER" module so that it displays a descriptive error message to the person filling out the form if if/when they try to submit a duplicate username.
It's my understanding that -- using PHP -- it's possible to sniff out what kind of database error message/number was encountered, and to perform certain actions based on that. How would I do something like that? More specifically --- what kind of PHP scripting would I need to add to handle a MySQL database error message that pertains to the "UNIQUE" constraint being encountered?
Thanks in advance!
- Yvan
Start Free Trial