Error message for duplicate entires to a database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
GavW
Forum Newbie
Posts: 2
Joined: Wed Mar 22, 2006 5:46 pm

Error message for duplicate entires to a database

Post 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
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post 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
Post Reply