Member Data Submission

Hi all, I’ve currently got a website set up with a wix members area for login and am trying to allow users to submit scores to a database which is then shown in a leaderboard format. I wanted to create new fields on one of the existing members area databases but both are marked read only. I have created a secondary database for people to submit to but even though the form to submit to this is on a dynamic page each person who submits overwrites the same entry rather than creating a new one. Can anyone recommend some code for my dynamic page which will allow people to submit data to the secondary database which they can update their own later but each unique user creates a new line in the database?

Since you already have the secondary database setup, you’ll need to create a custom field in their account page and use custom code to update the number.

Not the complete code below but maybe it could help you start??

import wixUsers from 'wix-users';
import wixData from 'wix-data';


$w.onReady(function () {
let user = wixUsers.currentUser;

let userId = user.id;           // eg: "r5cme-6fem-485j-djre-4844c49" will get the user details
let isLoggedIn = user.loggedIn;


console.log(userId);
  
wixData.query("testdatabase") //add name of your secondary database
  .eq("title", userId) //title is your database key where the userid from members db is stored
  .find()
  .then( (results) => {
    if (results.items.length > 0) {
      let items = results.items;
      let item = items[0];
      let scores = item.scoredata; //scoredata is your db key in the secondary db
    
      //now add your own data to edit and update the scores.    

    } else {
      console.log("nothing found");
    }
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );