Buy Now
Sign in

Save Data to Two Tables - Again

kkurtz , December 11 2019, 20:16
K
kkurtz 148
December 11 2019, 20:16 #390320
I thought I had this figured out . I had an earlier post on December 3, which was answered. However obviously I am losing it because I can't get this to work.
I am trying to save data to two tables - the Joomla user table and another table which is related.
I have a list which successfully displays data from both tables and I am able to call up a form, edit information in both tables and successfully save to both tables.
However I am not able to add records to both tables. The tables are related as follows:
First model is Info with table newuserinfo . The second model is Users (Joomla users table) and is related to Info where Relation is "One matching record, foreign key at the related table." The foreign key is userfile_id in the Info table.
I call up a form which has the text boxes for the pertinent information for both tables.
The save event is
{fn:save_core_user_info}
{fn:check_added_user_save_result}
{fn:save_info}
{fn:check_added_contact_save_result}.
The save_core_user_info uses the Save User action and is successful.
But the save_info action is not successful in that it saves to the table but the userfile_id is zero and there is no other data.
My save_info action parameters look like this:
Database table: newuserinfo
Write action: Insert
Data provider: {var:save_core_user_info.Users.id}
Model: Info
For overrides I have:
overrides.PNG
Where am I going wrong?
K
kkurtz 148
December 16 2019, 12:40 #390378
Please respond!
GreyHead 64
December 17 2019, 10:05 #390391
Hi kkurtz,
I suggest that you turn the Debugger on so that you can see the MySQL queries that are being generated. That should let you pin down the error.
I assume that this is a ChronoForms query and not ChronoConnectivity?
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
healyhatman 8
December 17 2019, 13:17 #390400
Shouldn't it be {var:save_core_user_info.Users.id} ?
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store
K
kkurtz 148
December 17 2019, 15:42 #390402
I tried that again both in the data provider and override fields and I get this message
[h2]#1048 Column 'userfile_id' cannot be null[/h2]
I have a debugger in the event but it doesn't get to that only the message above.
K
kkurtz 148
December 17 2019, 15:45 #390403
One more thing. In a prior test I put a debugger after the user file save and it is returning the id from the user file. That save is successful.
admin 28
December 17 2019, 19:17 #390407
Hi,
Please open the table in phpmyadmin and enable the NULL flag for all fields except the primary keys in order to avoid the error!
2nd, use the debugger to check which data was actually saved to the table, is {var:save_core_user_info.Users.id} a valid value you have already ?
Best regards
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
K
kkurtz 148
December 17 2019, 19:32 #390409
Max,
I have changed phpmyadmin as you suggested.
On the second issue I am not exactly sure what you are asking. Here is the debugger output.
Array
(
[save_core_user_info] => Array
(
[_success] => User saved successfully under id 121
[var] => Array
(
[name] => Ninety Six
[username] => 969696
[email] => ninety6@somewhere.com
[password] => nsix
[block] => 0
[activation] => 0
[registerDate] => 2019-12-17 17:54:51
[id] => 121
)

)

[check_added_user_save_result] => Array
(
[finished] => 1
[var] =>
)

[save_new_info] => Array
(
[data] => Array
(
[firstname] => Ninety
[lastname] => Six
[homeclub] => Soule Park
[officerclub] => Birch Hills
[member] => y
[president] =>
[delegate] =>
[handicap] =>
[membership] =>
[board] =>
[userfile_id] =>
[created] => 2019-12-17 17:54:51
[user_id] => 23
)

[_success] => Data saved successfully
[log] => Array
(
[0] => INSERT INTO `newuserinfo` (`firstname`, `lastname`, `homeclub`, `officerclub`, `member`, `president`, `delegate`, `handicap`, `membership`, `board`, `userfile_id`, `created`, `user_id`) values ('Ninety', 'Six', 'Soule Park', 'Birch Hills', 'y', '', '', '', '', '', ' ', '2019-12-17 17:54:51', '23');
)

[var] => Array
(
[firstname] => Ninety
[lastname] => Six
[homeclub] => Soule Park
[officerclub] => Birch Hills
[member] => y
[president] =>
[delegate] =>
[handicap] =>
[membership] =>
[board] =>
[userfile_id] =>
[created] => 2019-12-17 17:54:51
[user_id] => 23
[aid] => 1269
)

)

[check_added_contact_save_result] => Array
(
[finished] => 1
[var] =>
)

)
admin 28
December 17 2019, 19:38 #390410
I mean the "userfile_id" value is empty, where are you trying to get its value from ?
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
K
kkurtz 148
December 17 2019, 21:42 #390414
I am using a form to add data to two tables. The form contains fields for both tables - the Joomla user table (Users) and a related table (Info). The tables are related by Users.id and Info.userfile_id. So I save the data to the user table first and then to the Info table. I want the Info.usersfile_id to equal the Users.id. As you can see in the debugger above the id in the Users table is being saved but is not being passed to the Info table.
Karen
K
kkurtz 148
December 17 2019, 21:44 #390415
I should mention that I am using the "old" form view fields as I just modified an existing form.
admin 28
December 26 2019, 11:28 #390488
Hi,
According to the debug data, the path to the saved user id should be:
{var:save_core_user_info.id}
if this code is used after the user is saved, it should contain the user's id!
Best regards
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
K
kkurtz 148
December 26 2019, 19:14 #390497
Thanks, Max. that works. So simple.