Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2012
    Posts
    8

    Unanswered: PLEASE help - query failed: Duplicate entry '2' for key 'PRIMARY

    Hello guys, I'm trying to modify a specific row in a table.

    $paper_id = 2A
    $query = "UPDATE book SET paper_id='$paper_id', title='$title'";

    I'm getting this error <<query failed: Duplicate entry '2A' for key 'PRIMARY'>>

    Structure:
    Column: paper_id
    Type: Char
    Length: 20
    Deafult: None


    Can anyone please help me with this?

  2. #2
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,800
    Provided Answers: 11
    Does the ID "2A" already exist in the table?

  3. #3
    Join Date
    Apr 2012
    Posts
    8
    no, the value in the table is different.

    i.e. the paper_id is "3A"
    When i'm trying to modify it, I'm getting the duplicate error.
    $paper_id = 2A
    $query = "UPDATE book SET paper_id='$paper_id', title='$title'";

  4. #4
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Code:
    $paper_id = 2A
    $query = "UPDATE book SET paper_id='$paper_id', title='$title'";
    In the code is no WHERE clause. You are setting those two columns in all the records in that table to the very same values.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  5. #5
    Join Date
    Apr 2012
    Posts
    8
    Ooooh yeah you are right.
    Cheers mate

  6. #6
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    You're welcome.

    Thanks for the beer. 16 now.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Posting Permissions

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