SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a table "Members" with the following 3 fields: userid (int, primary key, auto_increment), email and name.

    I use the following line to enter members in the table:

    $results = mysql_query("INSERT INTO Members (email,name) VALUES ('$email','$name')");

    I never specify the value of the userid field, this is done automatically. But is there a way to know what userid a member received without doing a database search? I need this userid value to enter in another table that contains all the input of the new member.

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use this:
    PHP Code:
    <?php
    $userid 
    mysql_insert_id();
    ?>

  3. #3
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    int mysql_insert_id ([int link_identifier]) 
    this will return you auto increment field value from last query executed in script
    PHP Code:
        $link mysql_connect ("localhost""username""secret")
            or die (
    "Could not connect");
        
    $results mysql_query("INSERT INTO Members (email,name) VALUES ('$email','$name')"); 
        
    $id mysql_insert_id($link);
        
    mysql_close ($link); 


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
  •