Insert not working on live site!

Hey fellow Wixers,

I need your help or advice about some code that I have been trying to get working for the last 2 days.The annoying thing is that I’m so close but I just don’t know what I’m doing wrong or what I’m missing. I have looked everywhere online and everything is leading me to the code that I have made below.

Let me explain what I’m trying to do.

I have created a custom user/member registration page using code. Once the user creates an account I want to take the newly creates Memeber ID and insert it into a coloum called “memberName”( which is a reference field) in a collection called “Notifications”. I want to use the user ID so I can match the information in the “Members/PrivateMembersData” and my “Notifications” collection to allow users to perform actions on their account.

The problem that I am facing is that the insert action is not working on a live site and I’m not to sure why.

If anyone can help I would be great full.

1 Like

You can look at using this simple tutorial here for creating a members profile.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

You can keep the dataset as Members in the tutorial or you can change it to Notifications to match your existing setup.

I have used this myself and have it in a website along with the Wix Members app.

As you simply want to use the members userID, then there will be no need to have to insert anything extra as the ID will be the same in the Wix Members app Members/PrivateMembersData collection and the additional dataset that you make for the above tutorial.

See this recent post for more info on code for signup/login lightboxes and setup.
https://www.wix.com/corvid/forum/community-discussion/custom-login-1

Also, looking at your code and I can see that you use Wix Location API and the to function to take the user to your create an account address page.

Therefore note that anything you have written in code afterwards will not be running as the user will be moved onto another page before that code has the chance to run itself.

If you wanted it to be inserted into another dataset, you would need to move the Wix Location line to after your data has been inserted.

@givemeawhisky Hi, I’m having a similar issue.
Insert works perfectly on the preview but nothing happens on the live site. Could you please help me?

My code is as follows:

import wixUsers from ‘wix-users’ ;
import wixWindow from ‘wix-window’ ;
import wixData from ‘wix-data’ ;
let registration;

$w.onReady( function () {
$w( “#register” ).onClick((event) => {
console.log( “Button was clicked” );
$w( “#errorMessage” ).collapse();
$w( “#emailExists” ).collapse();
if ($w( “#email” ).valid && $w( “#password” ).valid && $w( “#company” ).valid && $w( “#name” ).valid) {
registerPerson();
console.log( “Trying to register” );
} else {
$w( “#errorMessage” ).expand();
console.log( “Missing Information” );
}

}) 

});

function registerPerson () {
let email = $w( “#email” ).value;
let password = $w( “#password” ).value;
let name = $w( “#name” ).value;
let company = $w( “#company” ).value
let toInsert = {
“name” : name,
“company” : company,
“email” : email
};
wixData.insert( “Members” , toInsert)
.then( (results) => {
let item = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
} );
wixUsers.register(email, password, {
contactInfo: {
“name” : name,
“company” : company
}
})

    .then((result) => { 
                wixWindow.openLightbox( "confirmation" ); 
    }) 
        . **catch** ((err) => { 

let errMsg = err;
console.log(err);
$w( “#emailExists” ).expand();
} );

}

@annitacaniglia Hi,

Its best to make a new post if you need help. Helps us keep the forum clean.

Regarding your issue: check your database permissions, perhaps your ‘Write’ permissions is set to ‘Admin’ only which is the reason its getting inserted in the preview mode and not on live.

Article: https://support.wix.com/en/article/about-collection-permissions

@shantanukumar847 It’s not, it’s set to site member. I’ll make a new post.