Page 1 of 1

Error message for duplicate entires to a database

Posted: Wed Mar 22, 2006 5:55 pm
by GavW
Hey all!

Im trying to catch an error and display in on my .php page.

I am using PHP4 which means im unable to use the try and catch method as i believe this is only available in the newer PHP5.

Im attempting to give a lecturer the option to add students to the module in which they teach. I have this working fine except that when i attempt to add a student that already exists in the module my site breaks and displays "Duplicate entry '2-1' for key 1" error message. This is what i would like it to do although i would like to display a message indicating this on one of my pages without anything breaking.

could anyone aid me with the code required to perform this function?

Thanks in advance.

GavW

Posted: Wed Mar 22, 2006 7:06 pm
by Deemo
when you use the mysql_query() method, add a die() statement at the end of it

http://us3.php.net/manual/en/function.mysql-query.php will help