Forums

Save data in multiple tables

annekm 09 Jun, 2017
Hi,

I am trying to save data from a form to multiple tables.

The form is for a transaction. For each transaction, data with the transaction details should get updated in Transactions table.
The Email and total should be updated/inserted in the Master table. In the Master table, Email id should be unique. So if the total is changed, the Master table should be updated.

I created both tables based on the form from Chronoforms.

I used the first DBSave to Insert the data into Transactions table.

Next I inserted a Custom Code to Unset the 'id' field.



<?php
unset($form->data['id']);
?>



Next I used a DB Read on the Master table to find a Matching field.
On Success, I update the Master table and On Fail, I Insert the data into the Master table.

The issue I am facing is, the data is updated/inserted into the Transactions table for both the Actions.

I tried changing the order of the DB actions and found that the table in the first DB Save action only was getting updated for both.

Can you help me resolve this issue?
GreyHead 09 Jun, 2017
Answer
Hi annekm ,

I'm sorry I can't work out where the problem is from the info you have posted here. This sounds as though it is just a question of getting your logic 'right' to make the saves you need. You might be better doing the second save with custom PHP rather than using CF DB Save actions.

Bob
annekm 12 Jun, 2017
The unsetting of the id field was wrong.

I had copied the code from the forum directly without changing the field name 😶

I changed it to 'id' and it worked.

<?php
unset($form->data['cf_id']);
?>


Thanks
This topic is locked and no more replies can be posted.