Hello everyone!
Sometimes when i access my page i get this error message:
Duplicate entry '2' for key 1
Can anyone explain me what may cause this kind of error?? I believe it has to do with the database connection(??!)....
Thanks in advance!
Help with "duplicate" error message
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Oops, sorry!...jmarcv wrote:First, this is a database question, not php.
Well, i don't understand what you mean with "user error": is it when someone clicks more than once on the same link (a link that is used to insert/update values in the database), without waiting for a response from the server? Like when someone is "on a hurry" it registers twice the same information?!
Any help is welcomed!
This is an old problem. The way I solve it is to (now its not php OR database!) use Javascript. Set a variable in javascript to zero. in the form tag, put an onSubmit line that executes a javascript procedure to check the variable. If it is zero, set variable to 1 and return true to process the form. If it is 1, pop up nasty message about the need for patience in life, return false to keep form from submitting. For good measure, I usually change the prompt on the button from 'Submit' to 'Processing'
The PHP way is to have your insert check to see if the record is in the DB first, and branch to a message section similar to the nasty message mentioned above if it is..
The PHP way is to have your insert check to see if the record is in the DB first, and branch to a message section similar to the nasty message mentioned above if it is..