Okay, I found the correct function and below is what I have: - Show quoted text - $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') SELECT scope_identity() INSERT INTO table2 ( credit_card_id, case_number, comments) VALUES ( 'scope_identity', '$case', '$comments')"; echo "$insert1"; mssql_query($insert1) or die ("Query failed: <br />".mssql_get_last_message()); echo "Insert complete"; the scope_identity function is suppose to select the last inserted ID for the first insert statement. When my query executes, it "appears" to go thru all the steps correctly...it inserts the first record just fine, displays the echo of my query and returns the echo of "Insert Complete" HOWEVER, when I go to look at the data base there is NO data inserted into table2 even though my query returned that "Insert Complete" statement. Any ideas? On 2/14/07, Jim Lucas <lists@xxxxxxxxx> wrote:
Brad Fuller wrote: >> >From looking on the web (MSDN) I found the @@identity and the explanation >> of >> what it is, but MS's "example" is horrible and does not show a good >> context >> for using this function. Could you elaborate more on its use? > > $q = mssql_query("INSERT INTO TableName(...) VALUES(...) SELECT > LAST_INSERT_ID=@@IDENTITY"); > $r = mssql_fetch_assoc($q); > > > HTH, > > Brad > Might look at this http://us3.php.net/manual/en/function.mssql-query.php#46026 -- Enjoy, Jim Lucas Different eyes see different things. Different hearts beat on different strings. But there are times for you and me when all such things agree. - Rush