I have a submission form that returns a MySQL error #1062 when a user tries to submit it with a duplicate entry. As an example, the error states:
Duplicate entry 'graphics' for key 'name'
I want to give the user a custom message that explains (in plain English) why they got an error, and what specific entry caused the error. For example:
"Graphics" is a duplicate entry and should not be used. Please remove it and resubmit the form."
The key will always be ‘name,’ but the duplicate entry itself will often be different. I need to be able to pull that specific value out of the MySQL error that’s generated, and then wrap my custom message around it. How could this be done?
You could try to make a simple error check, displaying the user your error message if a mysql error occurs. You could try something like this: