Submit/Save Button adds inputs to two different databases.

Hello House,

I am seriously in need of a Code that i can add to a page on my site that will allow one user input data to be submitted on two Database at the same time. I got something like this below,

export function button12_click(event, $w) {
let gteamname = {
“gteamName”: $w(" #input26 ").value,
“hteamName”: $w(" #input23 ").value,
“gteamPict”: $w(" #uploadButton2 ").value,
“hTeampict”: $w(" #uploadButton4 ").value,
};
console.log(“person to be saved” + JSON.stringify(gteamname));
wixData.insert(“MATCH_SUMMARY”, gteamname)
}

But i need explanation on how this person got to this place and what all these means.

I need something generic that i can customize to fit my site.

I will be extremely grateful if any response is posted here and on time too.

Thanks.

Hello!

1-you can use wix Data and insert function to insert the same data to more that one collection:

import wixData from 'wix-data';

let gteamname = {
		"gteamName": $w("#input26").value,
		"hteamName": $w("#input23").value,
		"gteamPict": $w("#uploadButton2").value,
		"hTeampict": $w("#uploadButton4").value,
	};

wixData.insert("myCollection1", gteamname) 
	.then( (results1) => {
		let item1 = results1; //see item below
	} )


wixData.insert("myCollection2", gteamname) 
	.then( (results2) => {
		let item2 = results2; //see item below
	} )

2-you can add a hook that saves to the second data base after/before you inserted to the first one.

that’s for saving in two collections, as for on how this person got to this place and what all these means,
i don’t seem to understand fully what you mean. if you want to know from what address did a user come from you can check referrer here.

Best!
Massa