# How to automatically add "Wix Members ID's" to a database?

**URL:** <https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877>\
**Category:** Ask the community\
**Tags:** wix-members-area, question, code\
**Created:** [June 1, 2018, 8:11pm UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877 "2018-06-01T20:11:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordantaylor4456](https://avatars.discourse-cdn.com/v4/letter/j/8edcca/32.png) [@jordantaylor4456](https://forum.wixstudio.com/u/jordantaylor4456)\
**Post date:** [June 1, 2018, 8:11pm UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/1 "2018-06-01T20:11:25Z")

</div>

I’ve looked all over and have found many articles/Q&A answering my question that are similiar but not exactly what I’m looking for. I think the answer is right in front of my face but I can’t seem to get it… Trying to explain this as easy as I can… A New Member signs up on my website, (that user has a unique Wix Member ID). How do I get each new member’s unique Wix ID to automatically be added to my database? Im creating private dynamic member pages based on the Wix Member ID but can’t figure this part out. Thank you in advance for your time and any information is very much appreciated.

---

<div class="post-metadata">

**Author:** ![ammar-alhodaibi](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ammar-alhodaibi/32/3018_2.png) [@ammar-alhodaibi](https://forum.wixstudio.com/u/ammar-alhodaibi)\
**Post date:** [June 1, 2018, 9:04pm UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/2 "2018-06-01T21:04:55Z")

</div>

Dear :

i use this code  
you need to sign out and sign in to let the code check your id

this will check the ID then insert it to the collection if is not in the collection  
it’s will check the field number “acnumber” in Members  
acnumber = 1000  
randf = 1000+1  
and it will add title “student1001”  
I hope this will help you

```javascript
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';

$w.onReady( () => {

user = wixUsers.currentUser;
 userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
 user.getEmail()
  .then( (email) => {
     userEmail = email; // "user@something.com"
  } );
    wixData.query("Members")
    .descending("title")
     .find()
      .then( (results) => {
         rand = results.items[0]["acnumber"];
    randf = `${Number(rand) + 1}`;
    addrand = ("student"+randf);

} );
  
});
export function button1_click() {

 // user is logged in
 if(wixUsers.currentUser.loggedIn) {
 // log the user out
            wixData.query("Members")
          .eq("_id", userId)
          .find()
         .then((results) => {
 let prrcon = results.items[0]["pr"];
 // if an item for the user is not found
 if (prrcon === "superadmin"){
         wixLocation.to('/supervisor');
       }
 
 else if(prrcon === "admin") {
             wixLocation.to('/supervisor');
         }
 
 else if (prrcon === "subadmin" ) {
            wixLocation.to('/supervisor');
             }
 else if (prrcon === "teacher" ) {
            wixLocation.to('/stu-tsmya');
            }else {
                $w('#text44').show();
                } 
             });
  }
 // user is logged out
 else {
 // prompt the user to log in 
    wixUsers.promptLogin( {"mode": "login"} )
      .then( (user) => {
        userId = user.id;
 return user.getEmail();
      } )
      .then( (email) => {
 // check if there is an item for the user in the collection
        userEmail = email;
 return wixData.query("Members")
          .eq("_id", userId)
          .find();
      } )
      .then( (results) => {
 // if an item for the user is not found
 if (results.items.length === 0) {
 // create an item
 const toInsert = {
 "_id": userId,
 "email": userEmail,
 "pr": normal,
 "title": addrand,
 "acnumber": randf
          };
 // add the item to the collection
          wixData.insert("Members", toInsert)
            .catch( (err) => {
              console.log(err);
            } );
        }
 // update buttons accordingly
        $w("#button1").label = "Go to control";

      } )
      .catch( (err) => {
        console.log(err);
      } );
  }

 
  }

```

Br

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [June 3, 2018, 4:28pm UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/3 "2018-06-03T16:28:04Z")

</div>

Hi all!

If we’re talking about the same thing, and you’re saving the members data correctly to the database, the ID is already generated.

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/2/d21795e2f95caddf6fee06fbffb943477774d097.png)  
simply press on the “Visible fields” tab in the database’s page and check the “ID” to show it.

**How to use it?**  
For example, using the [wix-user](https://www.wix.com/code/reference/wix-users.html) API you can get the current user’s ID and compare it to the IDs that are saved in your database.

If I got you wrong and you mean something else, please elaborate and I’d be glad to help further more.

Doron. 🙂

---

<div class="post-metadata">

**Author:** ![jakworthington](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jakworthington](https://forum.wixstudio.com/u/jakworthington)\
**Post date:** [August 6, 2018, 9:50pm UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/4 "2018-08-06T21:50:09Z")

</div>

Hi Doron!

I tried what you said above, however, the ID is different for every submission from same logged in user. Is it possible to have each logged in user to have an ID or is the ID only for each entry?

Thank you!

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [August 7, 2018, 9:46am UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/5 "2018-08-07T09:46:29Z")

</div>

Hi Jack!

In cases like this it is better to use a similar but different field called “\_owner”.  
You can find it the same way as the \_ID and its purpose is to link between of all the items belongs to the same user who submitted/own them.

Check [this](https://support.wix.com/en/article/about-database-collections#system-fields) article for further information.

Doron.

---

<div class="post-metadata">

**Author:** ![jakworthington](https://avatars.discourse-cdn.com/v4/letter/j/9e8a1a/32.png) [@jakworthington](https://forum.wixstudio.com/u/jakworthington)\
**Post date:** [August 7, 2018, 2:31pm UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/6 "2018-08-07T14:31:28Z")

</div>

Hi Doron!

Thank you for your help! The \_owner option works perfectly! Do you happen to know if I can pull the user’s email from their owner number? I’d like to be able to email them depending on the number/type of responses they submit into my database.

Thank you for the help!

- Jack

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [August 7, 2018, 2:49pm UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/7 "2018-08-07T14:49:47Z")

</div>

Hey Jack!

Sure ya can!  
Check out our [Wix-Users API](https://www.wix.com/code/reference/wix-users.html#currentUser) .  
It even has an example exactly for pulling the logged-in user’s Email.

Doron.

---

<div class="post-metadata">

**Author:** ![l\_odea](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/l_odea/32/18067_2.png) [@l\_odea](https://forum.wixstudio.com/u/l_odea)\
**Post date:** [April 7, 2020, 10:40am UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/8 "2020-04-07T10:40:57Z")

</div>

Hi Doron, I just came accros your comment above about ID’s and am hoping you can help me please? My question is, do I need to add ome kind of code to connect data that’s entered from a member on a page that’s connected in a data set but is somehow getting transferred to the data set but not corresponding to the right persons ID?

---

<div class="post-metadata">

**Author:** ![ubilav](https://avatars.discourse-cdn.com/v4/letter/u/b19c9b/32.png) [@ubilav](https://forum.wixstudio.com/u/ubilav)\
**Post date:** [May 4, 2021, 11:25am UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/9 "2021-05-04T11:25:35Z")

</div>

hello, on my site I have a “register” page which saves emails in a database, I have a my account page with a form on it which takes additional information about this user once he is connected, How do I add the additional data from the form next to the email of the member of my site in the database without asking for his email again (because he is already connected)?

---

<div class="post-metadata">

**Author:** ![habsha-1996](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/habsha-1996/32/25365_2.png) [@habsha-1996](https://forum.wixstudio.com/u/habsha-1996)\
**Post date:** [November 22, 2022, 3:36pm UTC](https://forum.wixstudio.com/t/how-to-automatically-add-wix-members-ids-to-a-database/39877/10 "2022-11-22T15:36:23Z")

</div>

I need to create a datbase that would contain the mark of my students and display their results using ID number.can anyone help me
