Insert today date to database for current user via button

I have a button on a dynamic page and my goal is to write (or overwrite if it has a previous value) today-date to database ( to the current user’s specified column “lastpaymentdate”) via this button.
My code is not working well, because it has create a new row in database and write today_date here :frowning:

export function button10_click(event, $w) {
wixData.query(“Members”)
.eq(“_id”, wixUsers.currentUser.id)
.find()
.then ((put) => {
if (put.items.length===1){
let toInsert = {
“lastpaymentdate”: Date()};

wixData.insert(“Members”, toInsert)
.then(() => {
// go to welcome page
wixLocation.to(“/successprofileupdate”);
})
. catch ( (err) => {
console.log(err);
} );

}

});
}

Thx in advance!
Imre

Dear :

insert( )

Adds an item to a collection.

update( )

Updates an item in a collection.
https://www.wix.com/code/home/forum/questions-answers/insert-today-date-to-database-for-current-user-via-button

Br

Thx, I checked update function and tried these versions but nothing happens in the database (I have checked permissions and set everything to anyone):

1,
export function button10_click(event, $w) {
$w(“#dynamicDataset”).setFieldValue(“lastpaymentdate”, new Date()); }

I see the date in the field on the page but the button click not push it into the database

2,
export async function button10_click(event, $w) {
let item = await wixData.get(“Members”, “lastpaymentdate”);
item.lastpaymentdate = new Date();
await wixData.update(“Members”, “lastpaymentdate”) }

Has the same results than 1st try.

3,
export function button10_click(event, $w) {

wixData.query(“Members”)
.eq(“_id”, wixUsers.currentUser.id)
.find()
.then((results) => {
let oldlastpaymentdate = results.items[0].lastpaymentdate;
let newdate=Date();

//adding all the fields of the record
let toUpdate = {
newdate: oldlastpaymentdate,
};

  updatePassword(toUpdate); 
}); 

function updatePassword(toUpdate){
wixData.update(“Members”, toUpdate)
.then((results) => {
console.log(“item was undated sucessfuly”);
})
. catch ((err)=>{
console.log(err);
});
}

This version still not push date into database.
It seems like ‘submit’ functions missing which push data into database.

Thx if anybody can help!

Dear :

Try this

$w("#dynamicDataset").setFieldValue("lastpaymentdate", new Date()); }
    if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined;
    } 
    debounceTimer = setTimeout(() => {
$w("#dynamicDataset").save();
    }, 200);

Br

Thank you so much It seems all these versions work but I forgot to connect the button to the collection and get the submit function. Now it works perfectly!