Array ( [DB Save] => Array ( [Queries] => Array ( [0] => INSERT INTO `#CCT-DBCompleta` (`p101inombre`, `p101iapellidos`, `p101inch`, `p101ifechanac`, `p101iedad`, `p101dhospital`, `p101dfechaingreso`, `p101dpeso`, `p101dtalla`, `p101dimc`, `user_id`, `uniq_id`, `created`) values ('Duplicado', 'Duplicado', 'Duplicado', '21-01-2016', 'Duplicado', 'Duplicado', '25-01-2016', 'Duplicado', 'Duplicado', 'Duplicado', '286', '65c1506d933901f2aa08101bb9a8a904c31f731c', '2016-01-28 03:09:09'); ) ) ) [10] => Array ( [DB Save] => Array ( [Queries] => Array ( [0] => UPDATE `#CCT-DBCompleta` AS `Data` SET `p101inombre` = 'Duplicado', `p101iapellidos` = 'Duplicado', `p101inch` = 'Duplicado', `p101ifechanac` = '21-01-2016', `p101iedad` = 'Duplicado', `p101dhospital` = 'Duplicado', `p101dfechaingreso` = '25-01-2016', `p101dpeso` = 'Duplicado', `p101dtalla` = 'Duplicado', `p101dimc` = 'Duplicado', `user_id` = '286', `modified` = '2016-01-28 03:09:09' WHERE `id` = '4'; ) ) ))"> Store form data in more than 1 table (2, 3, 4, etc.) - Forums

Forums

Store form data in more than 1 table (2, 3, 4, etc.)

Kronosites 28 Jan, 2016
Hello,

I'm trying to save all the information from 1 form into more than 1 table from same database.
All the information is saved correctly to the first table.
But the second "DB SAVE" action didnt save into the other table. In the debugger I see a "update" sql to the same table.
¿How can I save this information into more than 1 tables? (I need save all the info to 7 different tables).

Here you are my setup form:

- First DB SAVE use this table: #CCT-DBCompleta
- Second DB SAVE should use this one: #CCT-DBCompleta_duplicado

Here you are my debug info:
As you can see, first DV save adds a "INSERT INTO", but the second DB SAVE only adds an "UPDATE" to the same table.
Array
(
    [9] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `#CCT-DBCompleta` (`p101inombre`, `p101iapellidos`, `p101inch`, `p101ifechanac`, `p101iedad`, `p101dhospital`, `p101dfechaingreso`, `p101dpeso`, `p101dtalla`, `p101dimc`, `user_id`, `uniq_id`, `created`) values ('Duplicado', 'Duplicado', 'Duplicado', '21-01-2016', 'Duplicado', 'Duplicado', '25-01-2016', 'Duplicado', 'Duplicado', 'Duplicado', '286', '65c1506d933901f2aa08101bb9a8a904c31f731c', '2016-01-28 03:09:09');
                        )

                )

        )

    [10] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => UPDATE `#CCT-DBCompleta` AS `Data` SET `p101inombre` = 'Duplicado', `p101iapellidos` = 'Duplicado', `p101inch` = 'Duplicado', `p101ifechanac` = '21-01-2016', `p101iedad` = 'Duplicado', `p101dhospital` = 'Duplicado', `p101dfechaingreso` = '25-01-2016', `p101dpeso` = 'Duplicado', `p101dtalla` = 'Duplicado', `p101dimc` = 'Duplicado', `user_id` = '286', `modified` = '2016-01-28 03:09:09' WHERE `id` = '4';
                        )

                )

        )

)
GreyHead 28 Jan, 2016
Hi Kronosites,

First - it is bad design to save the same data in more than one table.

If you must do it then you need to unset the value of $form->data['id'] between the saves,

Bob
Kronosites 28 Jan, 2016
Hi GreyHead,

I know its a bad design. But I think its the only way to do what I need to do.
You say that I have to unset the value of $form->data['id'] between the saves. Sorry, but I dont have idea how to do that.
Could you explain it, please?

[...]
This is what I have, what I need and why I think I have to save same data into 7 different tables:

>>Objective:
I have a BIG form (7 pages with lot of information).
I need to make all the fields requiered, but I dont want to force the users fill the 7 pages at once.
In addition, users must be able users edit any data of any page whenever they want.

>>Solution:
- I create 1 first form in chronoforms with contain the main data of the register (f.e., name, passport, birth-data, etc.).
- I create 7 forms, 1 form per page.
- I create 7 different tables which contains the individual info of this page + the info inserted from first form.
- Only the first form is to "create new register".
- The others 7 forms is only to edit the data of different pages throught chronoconnectivity.
So, when a user "creates new register", only needs the main información (first form) and this info must to save in the 7 tables
And, when users need to edit, for example, some info about the page nº6, they go trought Chronoconnectivity to page6 (an url created to edit) and opens the "page6" form. This forms reads the info of table6 and saves to the same table.

I mean, I need to save the info of the first form into 7 different tables because the information of the pages is relative to the same "register", and the users must see the "main information" in all pages (to know what register want to edit).
GreyHead 28 Jan, 2016
Hi Kronosite,

You can still put all of this in one table and update the record in the later pages - you just need to keep the record id in a hidden input so that the same record is updated.

Please see this FAQ for the unset code.

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