Noob asking Noob questions...

Hey,
I’m building my very first website and so far have learned quite a bit.
But not knowing javascript makes it quite challenging to build custom functionalities…

I’m still building basic stuff and I have just done a login page following what the internet was telling me.
Now, I want to do some more and not so much more complex I though…

So, on my login page I have a button (“Profile”) that sends the user to his profile page (where he can update his details).
Now I want to add a new button (“Order”) that send the user to a page where her will be able to select different items but I want to use some info form the profile to dynamically populate the new page.

In my member profile database I have the used details including his child last name an first name (in 2 separate columns), this db uses the user id as unique key if I got that correctly.

My 2nd database contains the child last an first name and a few more field that I want to be able to populate via the new dynamic page. This db uses the child last and first name as unique key if I got that correctly again.

Now, when I add the onclick function as follow, my query on the member profile db return an empty array and I can’t get why that is…

export function button3_click() {
let userId = ${wixUsers.currentUser.id};
console.log(“1”,userId);
$w(“#button5”).label = userId;

return wixData.query(“MemberProfile”)
.eq(“_id”, ${wixUsers.currentUser.id})
.find()
.then ((results) => {
console.log(“3”,results.items);
let childLastName = results.childLastName_1;
let childFirstName = results.childFirstName_1;
console.log(“4”,childLastName);
$w(“#button4”).label = childLastName;
wixLocation.to(/MemberOrders/childLastName/childFirstName);
});
}

Hopefully that made sense and someone kind enough to read the whole thing can help me out…

Cheers.

Hey
Correct the following stuff first

let userId = ${ [wixUsers.currentUser.id](http://wixusers.currentuser.id/) };

should be

 let userId = wixUsers.currentUser.id;

Thanks Andreas. But I get the same result, empty array.

@thelunchboxfactorysy Abd you changed it here as well?
.eq(“_id”, ${ [wixUsers.currentUser.id](http://wixusers.currentuser.id/) }) to the above sample? What do you get in the console.log(wixUsers.currentUser.id) ?

@andreas-kviby Yes, made that change too.
The console.log(“1”, userId does give me the correct user id.

@thelunchboxfactorysy So are you in Preview mode or on the Published site? You can’t test and debug users very good in preview mode as you will always get the userId of you logged in as an Admin of the site. But before you get the correct userId you won’t get the correct data as well.

Also

 let childLastName = results.childLastName_1; // This won't work
  let childLastName = results.items[0]childLastName_1; // This will work and will give you the first items childLastName_1

@andreas-kviby I’m using both preview and publish as I figured out that the preview mode is not helpful for testing this. As a cheap trick I’ve used the button labels to display the id value in published mode. There must be a better way to do this but my knowledge is too limited at this stage…

Thanks for your help, I have to go now, will be back tomorrow for more code testing and messing around.

Cheers.

@thelunchboxfactorysy Ok what I would do is to study the wixUser in the API Reference and before you get the users id check that they are logged in and so on. There are lot of samples in the API Docs on how to do this. When you get the correct userId it will work. Also make sure cookies are not turned off because then you will most likely get a very weird userId.