smcan Posted March 16, 2009 Share Posted March 16, 2009 I have a very basic form (last name, first name, building, extension, email, request). Currently a user can fill out the form and submit and it will send an email as a work order for plant operations personnel and send a copy to the submitter. I want to use the ID number of the record as the work order number for user and operations personnel to track the issue. How can I get the ID number to add to the copy of the email going to the submitter? It seems it would have to connect to the database, get the next ID number, store it as a variable then do the rest of the script. Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/149686-send-next-id-number-as-workorder-number-in-email/ Share on other sites More sharing options...
xylex Posted March 16, 2009 Share Posted March 16, 2009 You need to store the record first, then get the id that was set when the record was stored. For mysql, you want to use mysql_insert_id()/mysqli_insert_id(); If you try to get the next number first, you setup a race condition where multiple threads could go at the same time and get the same number as the next insert id, but only one of them would actually use that number when the records are inserted. Quote Link to comment https://forums.phpfreaks.com/topic/149686-send-next-id-number-as-workorder-number-in-email/#findComment-786051 Share on other sites More sharing options...
smcan Posted March 16, 2009 Author Share Posted March 16, 2009 Thanks for the response. I had not though of the "race" condition. I'll check out those functions. Quote Link to comment https://forums.phpfreaks.com/topic/149686-send-next-id-number-as-workorder-number-in-email/#findComment-786090 Share on other sites More sharing options...
smcan Posted March 16, 2009 Author Share Posted March 16, 2009 Wanted to thank you again! The mysql_insert_id() function seems to have done the trick. I moved the mail() function until after the submit query in the script and added the mysql_insert_id() via variable to the body of the email message. Quote Link to comment https://forums.phpfreaks.com/topic/149686-send-next-id-number-as-workorder-number-in-email/#findComment-786142 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.