Page 1 of 1

Help with "duplicate" error message

Posted: Tue Jul 29, 2003 4:30 pm
by packito
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!

Posted: Tue Jul 29, 2003 9:31 pm
by jmarcv
First, this is a database question, not php.

It means you have a primary or unique index set up on your table, and you are trying to insert a record that has a value in the key field or exoression that already exists.
ie: user error

Posted: Wed Jul 30, 2003 4:45 am
by twigletmac
Moved to Databases.

Mac

Posted: Wed Jul 30, 2003 4:55 pm
by packito
jmarcv wrote:First, this is a database question, not php.
Oops, sorry!...

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! :?

Posted: Wed Jul 30, 2003 5:53 pm
by jmarcv
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..