Re: Error Control
| From: | CC Zona | Date: | Mon, 26 Mar 2001 17:21:40 +0000 |
| Subject: | Re: Error Control | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-7834@lists.php.net to get a copy of this message | ||
In article <NFBBIJOLMLCLDLEPPEDJGEJPCCAA.jbell@barkingrat.com>,
jbell@barkingrat.com ("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