WE have a unique key constraint on database table(safest approach to avoid duplicates) but when aware tries to add a record with duplicate directly shows database unique constraint error message. How do we modify this database message to make it user friendly? (shows Internal error- "error adding reference duplicate entry"
Constraint on a table-
ALTER TABLE table_name
ADD CONSTRAINT constraint_name UNIQUE KEY(column_1,column_2,...);
Unique key constraint mysql/maria internal error message
-
- Posts: 370
- Joined: Sat Apr 28, 2018 3:33 am
- Location: India
- Contact:
-
- Posts: 370
- Joined: Sat Apr 28, 2018 3:33 am
- Location: India
- Contact:
Re: Unique key constraint mysql/maria internal error message
How do we do below in aware?
https://stackoverflow.com/questions/102 ... or-message
$result = mysql_query('... query that produces duplicate key error ...');
if ($result === FALSE) {
if (mysql_errno() == 1022) {
die("Username already exists");
} else {
die(mysql_error());
}
}
https://stackoverflow.com/questions/102 ... or-message
$result = mysql_query('... query that produces duplicate key error ...');
if ($result === FALSE) {
if (mysql_errno() == 1022) {
die("Username already exists");
} else {
die(mysql_error());
}
}