Skip to main content
Topic: How to treat Mysql Error with unique constraint violation (Read 1072 times) previous topic - next topic

How to treat Mysql Error with unique constraint violation

I have a unique constraint in one of my tables in the database.

UNIQUE KEY `url_de_busca` (`url_de_busca`,`id_usuarios`),

This unique constraint forbids that two rows have the same values in these two fields.

When the user inserts a value that is already in the database, the following error appears



The error is correct, but I want to know how can I show a friendly error screen.

How can I do that?

 

Re: How to treat Mysql Error with unique constraint violation

Reply #1
@claudiomg‍ you can write your custom PHP code in Page Events, Action Before Add for the page you are working on, to check the values before adding it and alerting an error message to the user. Please also check the View Helper for PHP functions and variables to use.