For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > July 2005 > RE: [PHP-DB] Trapping a mySQL error









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RE: [PHP-DB] Trapping a mySQL error
Bastien Koert

2005-07-28, 4:00 am

<?
....
$result = mysql_query($query);
if (mysql_errno($result) == 1062)
{
echo "Already present in database";
}

?>

Bastien

>From: JM <frawst1@gmail.com>
>Reply-To: JM <frawst1@gmail.com>
>To: "php-db@lists.php.net" <php-db@lists.php.net>
>Subject: [PHP-DB] Trapping a mySQL error
>Date: Wed, 27 Jul 2005 17:13:09 -0700
>
>Hi all,
>I have a table with the record_id as the unique primary key and
>another column (the record_name) as unique as well. This is working
>how I want it to. I want unique record_names.
>
>When the user tries to add a record with an existing record_name the
>sql statement execution fails: error 1062. How could I trap this error
>and display a custom message to handle the situation better? Thanks in
>advance.
>
>John
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com