I have a unique key set for a mysql database row so not to insert duplicate entries on a form submit. That works fine, but if there’s a duplicate entry the page doesn’t load. Instead the user receives the warning: Duplicate entry ''' for key ''
How do I go about turning that error off and loading the page even if there is a duplicate key, while still using the unique key on the row? I tried setting error report to off, but that didn’t work.
mysql_query("INSERT INTO user
(formemail,UserIP,Timestamp,LP) VALUES('$email','$userip',NOW(),'$lp') ")
or die(mysql_error());
You need to change your SQL insert to use INSERT … ON DUPLICATE KEY UPDATE Syntax so that the error isn’t generated in the first place.
Don’t try to hide the symptom, treat the problem.
Also, I must point out that the mysql library is being deprecated and should not be used for new code, you should, at the least, use mysqli or, preferably PDO. There is a good tutorial on PDO here if you are interested in learning.