> -----Message d'origine----- > De : Tim [mailto:[EMAIL PROTECTED] > Envoyé : mercredi 14 février 2007 19:28 > À : 'Dan Shirah'; 'php-general' > Objet : RE: [PHP] Retrieve value of newly inserted row. > > > > > -----Message d'origine----- > > De : Dan Shirah [mailto:[EMAIL PROTECTED] Envoyé : mercredi 14 > > février 2007 19:20 À : php-general Objet : [PHP] Retrieve value of > > newly inserted row. > > > > Hello, > > > > I have a page the contains two insert statements. > > > > > > $insert1 = "INSERT INTO table1 ( > > debit_card, > > card_type, > > card_number, > > exp_date, > > payment_amount, > > cvv_number, > > first_name, > > middle_name, > > last_name, > > address_1, > > address_2, > > city, > > zip_code, > > zip_4, > > phone_number, > > fax_number, > > email_address, > > receipt, > > comments, > > date_request_received, > > employee_received_call, > > research_phase_date, > > research_phase_user, > > submit_phase_date, > > submit_phase_user, > > status_code, > > state_code) > > VALUES ( > > '$debit_card', > > '$card_type', > > '$card_number', > > '$exp_date', > > '$amount', > > '$cvv', > > '$cc_first', > > '$cc_middle', > > '$cc_last', > > '$cc_address_1', > > '$cc_address_2', > > '$cc_city', > > '$cc_zip', > > '$cc_zip_4', > > '$cc_phone_number', > > '$cc_fax_number', > > '$cc_email_address', > > '$receipt', > > '$cc_comments', > > '$create_date', > > '$create_user', > > '$research_date', > > '$research_user', > > '$submit_date', > > '$submit_user', > > '$status_code', > > '$cc_state')"; > > mssql_query($insert1) or die ("Query failed: <br > > />".mssql_get_last_message()); > > > > > > $insert2 = "INSERT INTO table2 ( > > credit_card_id, > > case_number, > > comments) > > VALUES ( > > 'card_id', > > '$case', > > '$comments')"; > > mssql_query($insert2) or die ("Query failed: <br > > />".mssql_get_last_message()); > > > > echo "Insert complete"; > > > > > > > > > > > > On my second insert statement, please note "credit_card_id". > > This is an > > auto_increment column in table1. What I need to do is pull > the value > > of "credit_card_id" from the newly inserted row from > insert1 and put > > that value in a variable to assign it to "credit_card_id" > in insert2. > > > > > > > > I hope that wasn't too confusing. > > http://cz2.php.net/manual/en/function.mysql-insert-id.php
Sorry my eyes played some tricks on me ragarding mysql/mssql refer to Robert's post on looking up "last insert id". Regards, Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php