List:General Discussion« Previous MessageNext Message »
From:Steve Buehler Date:May 8 2002 4:08pm
Subject:Re: inserting record
View as plain text  
Thank you.  Right after I sent that email, I found the same answer.
Now, I have another question about mysql_insert_id().  My code is below:
function updatedb($input){
         extract($input);
         $result=mysql_query("INSERT into team
         (name,mgr,asst_coach_1,asst_coach_2,coach,top,bot,alt_top,alt_bot,website)
         values
         (\"$name\", \"$mgr\", \"$asst_coach_1\", \"$asst_coach_2\", 
\"$coach\",
          \"$top\", \"$bot\", \"$alt_top\", \"$alt_bot\", \"$website\")");
         if(!mysql_insert_id()){echo "There was an error and the record was 
not inserted";
         }else{
                 $team_id=mysql_insert_id();
                 $result1=mysql_query("INSERT INTO team_season
                 (team_id,div_id)
                 values
                 (\"$team_id\", \"$div_id\")");
         }
}

If somebody else runs this function at the exact same time, will I have 
problems getting the results that I want?  The way the book reads, it 
sounds like it is per connection, so I should not have any problems with 
it.  I am just trying to make sure from the experts on this list.

Thanks
Steve

At 10:50 AM 5/8/2002, you wrote:
>SB>         I am running mysql with a php frontend.  I am trying to add 
>teams to a
>SB> table and when I do, it gives them a team_id number that is in an
>SB> auto_increment column.  This is no problem.  The problem is that I 
>need to
>SB> know that team_id so that I can also enter the team_id into another
>SB> table.  Any help would be appreciated.
>
>PHP has a function called mysql_insert_id(), which will give you the
>information you need.
>
>
>- Julie
>
>--> Julie Meloni
>--> julie@stripped
>--> www.thickbook.com
>
>Find "Sams Teach Yourself MySQL in 24 Hours" at
>http://www.amazon.com/exec/obidos/ASIN/0672323494/thickbookcom-20

Thread
inserting recordSteve Buehler8 May
  • RE: inserting recordJay Blanchard8 May
  • Re: inserting recordGeorg Richter8 May
  • Re: inserting recordRichard Emery8 May
  • Re: inserting recordJim Philips8 May
RE: inserting recordMax Anderson8 May
Re: inserting recordSteve Buehler8 May
Re[2]: inserting recordSteve Buehler8 May