1062 : Duplicate entry 'xxx' for key 2

Discussion in 'PHP' started by CasTex, Sep 19, 2010.

  1. #1
    Hello,

    When I try to mysql insert values with same names, it encourages this error. When I looked at the table column, I see that the row id is always "1" and it doesnt let to add same entry.

    [​IMG]

    My question is, how can I add an auto increment id to that column for adding same entry names?
     
    CasTex, Sep 19, 2010 IP
  2. tewman

    tewman Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You just need to Alter the table, add a new column (with a name such as 'id'), make it a primary key and make it auto-increment. This will create a primary key that is auto-incremented each time you add a new name, even if that name is the same as others.
     
    tewman, Sep 19, 2010 IP
  3. sunlcik

    sunlcik Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You should use command or phpmyadmin :

    1. ALTER TABLE `tb_name` ADD PRIMARY KEY ( `id` )
    2. ALTER TABLE `tb_name` CHANGE `id` `id` INT( 11 ) NOT NULL AUTO_INCREMENT
     
    sunlcik, Sep 19, 2010 IP
  4. CasTex

    CasTex Member

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Thanks but that is not working.

    My problem is, I can't add new user if the new user's firstname (aut_username) was used.

    [​IMG]

    I can add new column for firstname, but could you please tell me how to make it that lets you add same entry names.
     
    Last edited: Sep 20, 2010
    CasTex, Sep 20, 2010 IP
  5. seoforall

    seoforall Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    remove the primary key (unique) attribute from aut_username
     
    seoforall, Sep 20, 2010 IP
  6. sunlcik

    sunlcik Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Remove unique key...
     
    sunlcik, Sep 20, 2010 IP