The general way of handling this is to test for a duplicate index error number (1062) in the try/catch exception handler for the INSERT query (which you will need to add) and setup a message for the user letting them know that the value already exists. For all other error numbers, just rethrow the exception and let php handle it.