Help with "duplicate" error message

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
packito
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 1:53 pm

Help with "duplicate" error message

Post 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!
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Moved to Databases.

Mac
packito
Forum Newbie
Posts: 20
Joined: Mon May 19, 2003 1:53 pm

Post 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! :?
jmarcv
Forum Contributor
Posts: 131
Joined: Tue Jul 29, 2003 7:17 pm
Location: Colorado

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