In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] ("Jason Bell") wrote:

> Hello! I'm writing a script that validates a form.... It creates users in a
> mysql table, where there are 2 unique columns 'username' and 'email'.
> 
> I'm putting mysql_error() into a variable, but I don't want the end user to
> see that particular message... is there a way to look at just the key that
> has been duplicated, and create a custom error message for user display?
> 
> for example, when I duplicate a username, 'jbell', I get this from
> mysql_error() : "Duplicate entry 'jbell' for key 2"
> 
> I want to be able to see that the error is from key 2, and react
> accordingly....

>From a MySQL perspective, you could adjust the query so no error is 
generated.  See the syntax for "INSERT IGNORE" or "REPLACE" for instance.

>From a PHP perspective, there are functions such as set_error_handler() or 
register_shutdown_function() to deal with such issues.

<http://www.php.net/manual/en/features.error-handling.php>
<http://www.php.net/manual/en/ref.errorfunc.php>
<http://www.php.net/manual/en/function.register-shutdown-function.php>

-- 
CC

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to