Retrieve value of newly inserted row.

From: Date: Wed, 14 Feb 2007 18:20:12 +0000
Subject: Retrieve value of newly inserted row.
Groups: php.general 
Request: Send a blank email to php-general+get-248872@lists.php.net to get a copy of this message
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.

« previous php.general (#248872) next »