Buy Now
Sign in

Save Data to Two Tables

kkurtz , November 27 2019, 19:12
kkurtz 148
November 27 2019, 19:12 #390150
I am trying to save data to two tables which need to be related. I have read and tried the suggestions from an earlier post (Save form data into 2 tables, posted August 17, 2019 ) many times. But I guess I am missing something.
I am able to save data to the first table, which is the Joomla users table. I want to then use the id from that table and save it to another table so I can relate the two tables.
So I save the user data from a form. The model name for the user file is Users.
Then I read the user file as follows:
Name is read_users_id
Model is Users
Select type is First Matching record
Order is id, descending
Fields to retrieve is
According to the debug, the is retrieved successfully.
Then to save to the second table:
Name: read_info
Database table: newuserinfo
Write Action: Insert
Data Provider: {}
Model: Users
I have tried using Data Override using the name of the field in the second table and specifying what I want to to be set to
Set userfile_id to {} on insert
I have also tried to set a condition: userfile_id =
Apparently I am not using the correct syntax for the data I want to pass because am not getting a value for userfile_id.
Also, the primary key of the receiving table is aid and it is not being auto incremented.
So two issues, how can I get the correct value in the userfile_id field of the receiving table ?
And how can I cause the aid to be auto incremented?
Thanks for your help.
healyhatman 8
November 28 2019, 04:00 #390156
When you save into the first table, part of the data returned will include the created ID. No need to read the database looking for the newly created object, ESPECIALLY since the way you're doing it will run into problems if a new entry is saved to the database in between your save and read.
So it will be available as {var:save_data_action_name.ModelName.id_column_name}
Should probably also be using the Save User action, instead of saving directly to the table.
If the aid column in your other table is not being auto incremented, make sure you actually have it set to auto increment. Do that in PHPMyAdmin, or in Chronoform's table editor. But seriously just do it in PHPMyAdmin.
Web developer at - I DO NOT work for ChronoEngine!
Professional Work:
Custom CF / CC Plugins and Extensions:
healyhatman 8
November 28 2019, 04:04 #390157
The Data Source field takes an array of data, and matches up attributes in the array with the same named column. So that's not much use to you.
You say you're using {} as the data override - can I ask, are you typing LITERALLY that?
Web developer at - I DO NOT work for ChronoEngine!
Professional Work:
Custom CF / CC Plugins and Extensions:
kkurtz 148
December 03 2019, 19:40 #390217
Just FYI...I didn't get a notification that you had posted a reply. Is that supposed to be automatic? If so, it isn't working.
First, I was able to get the aid field to auto increment by using phpmyadmin.
I was able to save the second file with the id from the User file.
Thanks for your help.