Advertisement

07.12.2008 at 05:46AM PDT, ID: 23559531 | Points: 500
[x]
Attachment Details

How do you handle MySql database error messages using PHP / dealing with "unique" contraint?

Asked by IDEASDesign in PHP Scripting Language, PHP and Databases, MySQL Server

Tags:

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!
- YvanStart Free Trial
[+][-]07.12.2008 at 05:53AM PDT, ID: 21988912

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.12.2008 at 06:09AM PDT, ID: 21988957

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.12.2008 at 06:11AM PDT, ID: 21988967

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.12.2008 at 06:16AM PDT, ID: 21988980

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.12.2008 at 08:31AM PDT, ID: 21989461

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.12.2008 at 09:10AM PDT, ID: 21989569

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.16.2008 at 10:04PM PST, ID: 22973579

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-42 / EE_QW_2_20070628