Jump to content

Correct method to validate MySQL Inserts?


hoopz

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.