SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What does this error mean?

    Hey,

    I am trying to insert into my database and tried using mysql_error and have got this message:-

    Duplicate entry '127' for key 1
    What does this mean?

    Regards

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Well, there's a duplicate entry of 127 against key 1.

    One of your columns is marked unique and you already have an entry in there with a value of 127.

    Also, check to see if your column is of 'tinyint' data type, its limit is 127.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    it means you have attempted to insert a row with a value in one of the columns which duplicates a value that already exists in that column

    and now for a bit of crystal ball magic...

    change your auto_increment from TINYINT to something bigger

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    But i dont understand why that is happening. My table structure is shown below:-

    member_id - Auto Increment
    fname - VarChar
    sname - VarChar
    address - VarChar
    city_town - VarChar
    county - VarChar
    postcode - VarChar
    constituency - VarChar
    email - VarChar
    username - VarChar
    Now, the error is talking about member_id, its impossible to get the same value because its an incrementing value..

    I've got no idea why it does not work

  5. #5
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    Change Your Auto_increment From Tinyint To Something Bigger

    :d :d
    ^^
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  6. #6
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Thanks r937, thats worked.

    I had a look and there was no duplicate value, but for some reason changing the TinyInt and Int worked!

    Can you please explain why this was so i can keep this in mind in the future?

    Regards
    Billy

  7. #7
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Signed tinyint can hold values in the range from -128 to 127 (unsigned from 0 to 255). The column type hit its limit hence the error.

    You should change it to unsigned anything bigger than tinyint. If you keep the column signed then you're only using half of its capacity because you wont be using the negative range.

    Signed integers require one bit to indicate whether stored value is negative or positive.


Bookmarks

Posting Permissions

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