Re: Trap error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Mário Gamito" <gamito@xxxxxxxxx>
I have this form to submit a string to a postgreSQL table.
This table has UNIQUE property, so if someone tries to insert the same value more than once, PHP says:


"Warning: pg_exec(): Query failed: ERROR: duplicate key violates unique constraint "urls_negados_url_negado_key" . in /var/www/html/knet/boffice/insert_url_negado.php on line 4"

How can i redirect to a page informing the user of the fact, instead of this ugly warning ?

1. You should be using pg_query instead of pg_exec(). Note from pg_query() manual page:


Note: This function used to be called pg_exec(). pg_exec() is still available for compatibility reasons but users are encouraged to use the newer name.

2. You can adjust the error reporting level so warning are not shown. Look at the error_reporting level in php.ini or use the error_reporting() function. I don't use PG, but you should be able to then use something like pg_result_error() to capture errors like this and react accordingly.

---John Holmes...

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux