Insert, Get and Insert within the same foreach{}?!?

Discussion in 'PHP' started by jmansa, Mar 10, 2009.

  1. #1
    I'm trying to get this to work. I'm getting 5 userid's from a multiple select box. I now insert these 5 users into my dbtable like this:
    foreach ($_GET['multiple1'] as $userid) {  
    $result = $db->sql_query("INSERT INTO ".$prefix."_user_ref (old_userid) VALUES ('$userid')");
    } 
    PHP:
    This part works fine, and what that does is it gives the user a new userid in my table. My table is set with 2 fields (old_userid, new_userid). The new userid is made with auto_increment.

    Now my issue here is that I want to insert the users with the new userid into another table aswell within the same foreach{}. How do I get the new userid and then insert again in another table...

    Hope somebody can help...
     
    jmansa, Mar 10, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    mysql_insert_id()
     
    SmallPotatoes, Mar 10, 2009 IP