Jump to content

PHP database returning customization


plznty

Recommended Posts

The most direct solution is to execute the INSERT query, test if it failed or worked, and if it failed with a mysql_errno() value of 1062 (which corresponds to the Duplicate entry xxx for key yyy error), output the custom error message. This only requires some simple conditional logic to be added to test the mysql_errno() in the existing error checking logic that should already be present (everyone already has basic error checking logic if(){}else{} in their application on their queries, right?)

 

The second best way (requires two queries and more php logic) would be to execute a SELECT query to test if the username has already been taken, perform the logic to test how many rows were matched, output the custom error message if there is already a row, then execute the INSERT query if there is not.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.