When inserting data, can you insert parts of the form data into two different tables at the same time?
multiple Insert 'at same time'
Collapse
X
-
Yes. Just have two different MySQL statements in the file that the data is sent to:
[CODE=mysql]
mysql_query("IN SERT INTO table1 (var_a, var_b) VALUES($val_a, $val_c ) ")
or die(mysql_error ());
mysql_query("IN SERT INTO table2 (var_d, var_e) VALUES($val_b, $val_c ) ")
or die(mysql_error ());
[/CODE]
There might be a quicker way, but that's one way. -
When you mean by "at the same time" in "at the same time in real time", the answer is NO. These INSERT statements will be executed consecutively. When the second INSERT fails you have to make some code to retract the first one from the database.Originally posted by nathanwbWhen inserting data, can you insert parts of the form data into two different tables at the same time?
Another way is to include these statements in a "transactio n" where by you can commit (or rollback) a number of separate commands. See therefore MySQL documentation chapter Transaction model
RonaldComment
-
Comment