hoopz Posted August 12, 2008 Share Posted August 12, 2008 Hey everyone! Thanks in advance for your help! I am writing a function that Inserts data into 2 tables within a database. The Pseudo code is as follows: - insert into user_table ...... - get last id - insert into shipping_info ...... I'm a self taught in PHP/MySQL so I don't know all the proper coding practices. My question is this: if either of those inserts fail, especially the 2nd one, I need to remove any data that has been inserted and then generate an error message for the user. Here's what I'm thinking, please let me know if there is a better way to do this: - insert into user_table ..... - if success then continue else generate error message and return - get last id - insert into shipping_info ..... - if success then continue else remove data from previous insert, generate error message, and return Is this typically how it's done? Thanks again, - H Link to comment https://forums.phpfreaks.com/topic/119400-correct-method-to-validate-mysql-inserts/ Share on other sites More sharing options...
fenway Posted August 13, 2008 Share Posted August 13, 2008 How about transcatiosn? Link to comment https://forums.phpfreaks.com/topic/119400-correct-method-to-validate-mysql-inserts/#findComment-616080 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.