As already mentioned in your previous post from today about the same thing.
https://www.wix.com/corvid/forum/community-discussion/how-to-use-lastname-of-privatemembersdata-in-other-database?
You need to be using the current user from the Wix Users API
https://www.wix.com/corvid/reference/wix-users.html#currentUser
Not sure why you are using insert when you are just saving it to another dataset, however with your code listed above.
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
//TODO: write your page related code here...
});
export function button1_click() {
// create an item
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then((results) => {
//script here
$w('#text22').text = results.items[0].firstName;
})
let toInsert = {
name: $w("#text22").text, //name is the value wich I would like ti put into my database,
};
// add the item to the collection
wixData.insert("mannequin_preferences", toInsert). //mannequin_preference in the name of databse
.catch( (err) => {
console.log(err);
} );
}
You need to change it to this for it to work and show the site members first name in a user input box and insert it into the field in your other dataset.
You need to add the current user lines and to remove the closing curly bracket and parentheses before the insert function and add it after the insert, otherwise it will not run and not insert the value into the dataset.
Just note that in my code I have not added the ‘-’ in your dataset, you will need to add it if you wish to keep using your current dataset, along with using the field name and key of First Name (firstName) instaed of Name (name) as you have used.
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
});
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;
export function button1_click() {
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then((results) => {
$w('#text22').value = results.items[0].firstName;
let toInsert = {
firstName: $w("#text22").value
};
wixData.insert("mannequinpreferences", toInsert)
.then( (results) => {
let item = results;
})
.catch( (err) => {
let errorMsg = err;
});
})
}