SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Washington DC
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    issue with mysql_insert_id()

    I have:

    $sql = mysql_query("SQL Query");

    $rid = mysql_insert_id();

    $xref = mysql_query("insert into review_xref
    set rid = $rid,
    sid = $reviews[$i]");

    I keep getting this error:

    Duplicate entry '127-12' for key 1

    Any subsequent inserts into the xref table is attempting to insert with an rid of 127.

    I was not experiencing any problems with inserting into this table (xref) until now.

    It seems I can't insert into the xref table an rid > 127

    Error Message:
    MySQL said: Duplicate entry '127-9' for key 1.

    Query: INSERT INTO review_xref (rid,sid) VALUES ('129','9')

    I try to insert rid = 129 and sid = 9 but it tells me can't insert rid = 127 and sid = 9

    Any suggestions? Thanks!
    Last edited by Watson; May 4, 2002 at 12:10.

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2002
    Location
    Reykjavik, Iceland
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It has never worked for me, i´ve read about it on comments on php.net/mysql_insert_id that this is mysql version issue problem, this just doesn´t work on this version of php and with this version of mysql :/

    But you can use the mysql query LAST INSERT ID but then you are again doing a query to mysql that you are voiding with using mysql_insert_id.

  3. #3
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: issue with mysql_insert_id()

    weird, Watson, what version of mysql and php are you using? I have no problems with mysql_insert_id() function.

    Paul

  4. #4
    SitePoint Member
    Join Date
    Jun 2001
    Location
    Washington DC
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I figured it out.

    I had the rid column set to datatype of tinyint which limits the id to 127. I changed the datatype to int. That fixed it. My bad.


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
  •