Catching database errors (e.g duplicate key)

batvink 14 Feb, 2016

I want to confirm this is the correct process, before I implement it. It is possible for my users to enter values in a form that will result in a duplicate record in the database. (I have an auto-increment field, but field 'name' must also be unique).

This will produce an SQL error when the form is submitted. I need to catch this error. My process will be:

[list]Press submit
Perform a database read based on name field (to an external database)
If found, generate an error and run the event loop.
If not found, continue
Perform a database save.

Thanks for any confirmation or alternative process to do this.
GreyHead 15 Feb, 2016
Hi batvink,

Yes, that looks correct.

batvink 16 Feb, 2016
This topic is locked and no more replies can be posted.