Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Thanked 0 Times in 0 Posts

    how to avoid duplicate entry in database

    hello .. can anyone help me in inserting a duplicate entry in database?

    Actually i have a table "option" with 3 fields and two of them are set to primary key (composite). I have a poll descriptions in some other table (not concern here) and i have to put that poll's answers in table "option" and obviously when i insert data i should be like this

    poll_id answer_id answer_des

    1 1 myans_1
    1 2 myans_2
    1 3 myans_3

    the above data means that there is a poll with id=1 and it has 3 answers.
    first row is inserted easily but on second time it shows error of duplicate entry .. howdo i avoide it because i cannot remove the tag of primary key from "poll_id" and "field_id" .. Is there is any solution?

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    It sounds to me that the composite key is not actually in place, and only the poll_id is the primary.
    Run a describe on the table in question. Does it list that both the poll_id and answer_id are of type PRI for their keys? If these check out and list that the composite is in place, then the problem is you simply already have a record of 1 and 2 in the database before inserting OR your code is not updating the answer_id correctly before trying to insert it so that the second entry is trying to go in as 1 and 1 instead of 1 and 2.

    I just noticed this is in the other databases forum. What database are you using; DESCRIBE is a proprietary MySQL command.
    Last edited by Fou-Lu; 08-07-2011 at 03:41 PM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts