WixData Insert Not working [Solved]

Hi,

I would like to ask your help or suggestion as to why code below is not working when trying to retrieve user input then insert it into my collection. Please take note that there were instances wherein the code worked, but after a few tries it failed. I also tried to use the save function. Still the same, it works after a few attempts then fails.

Please let me know your thoughts. Thank you.


import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady(function () {
//TODO: write your page related code here…
});

export function button1_click() {
// create an item
let toInsert = {
“title”: $w(“#input1”).value, //fullName,
“email”: $w(“#input2”).value, //userEmail,
“password”: $w(“#input3”).value //password
};
// add the item to the collection
wixData.insert(“Collection01”, toInsert)
.catch( (err) => {
console.log(err);
} );
// go to welcome page
wixLocation.to(“/success”);
}

Hi,
Try this:

   wixData.insert("Collection01", toInsert)
           .then(() => {
            // go to welcome page 
            wixLocation.to("/success");
           })
           .catch( (err) => {
             console.log(err);
           } );
}

Roi

Hi Roi,

That fixed my issue. Thank you so much! : )

-Ron