SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    You want what? By when?? Milamber's Avatar
    Join Date
    Jan 2001
    Location
    California
    Posts
    342
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with complicated INSERT

    I have a table with 5 rows.


    UID (auto increment)
    username
    password
    email
    realname

    When i insert into it i only insert into the columns username, password, email, and realname. Now what i want to do is, once the data has been input, i want to get the value that gets put into UID for the input i JUST put in.

    How do i get that back?
    -Jeff Minard | jrm.cc - Battlefield 2 Stats

  2. #2
    :) delemtri's Avatar
    Join Date
    Jun 2001
    Posts
    579
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_query("select uid from table where username='$usernameyoujuststuckin'");

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there is a bit way of doing this, mysql stores the id of the result you just did.

    I know that i do it by doing

    $id = $db->last_id();

    but that is because i am using php_libs db class

    i think you need to use this funciton

    mysql_insert_id

    check the mysql manual for that function

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, mysql_insert_id does the trick
    http://php.net/manual/en/function.mysql-insert-id.php
    PHP Code:
    mysql_querry("INSERT INTO TableName VALUES ('foo', 'bar', 'zoot'");
    $insertID mysql_insert_id(); 

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Chris don't forget that last_id() function is not standard with the phplib distro and if you ever use a new copy of mysql_db.inc make sure to add that function into it.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yup, forgot to say that, my class has nice little comments along the line of

    // added by freedydoesphp, sitepoint threadid=blah etc..

    lol


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
  •