Automatic update

Hello wix users. I have one small issue regarding my site.
I have made a website only with 2 pages. Login functionality is there for page 1. After login when user click a button in page one, a container box in second page gets converted into green colour.
I am using wix storage ( local ) for this functionality. Now my requirement is that there are 50 users for my site. If One user changes the colour of container box in page 2, that colour change should be visible to all the login users in page two. Since i am storing the colour change in wix local as storage, is there any way that i can make that wix storage(local/session ) global so that if any user makes any changes then, that change should be visible to all the users using my wix site.

Please provide some sample code if this functionality is possible.
Note: I am not using any database. I am using wix storage(local/session) to store the colour changes in my website. I just want to make this changes available for everyone login users for my site.

Thanks!

The wix-storage API is for persistent storage in the user’s browser - that is, the contents of wix storage won’t affect another user’s browser. For what you are trying to do, you will need to use a simple database collection that stores the latest value which can be made available to other users. Keep in mind that more than one user may try to make changes at the same time.

1 Like

@yisrael-wix .
Thanks for your quick reply. I guess you are correct but i could not find any way to store container box in wix database , so i used wix-storage. If any way is there to solve my problem using wix-storage itself then it will be very helpful or if you can guide me how to store wix container box element in simple wix database.

Thanks.

As I said, wix-storage is specific for a user’s browser and won’t be seen by others. Instead, you will need to use a database to store the information.

@yisrael-wix

Thanks for guiding me. Please help me with below 2 issues

  1. I have a database with field email_id and and Slot. Now i have provided login option in my page one.
    If any user login to my site he will see a button. once he clicks that button i want to change the value of
    field Slot to green. How to achieve this.
    for example - suppose a user abc@gmail.com logs in into my wix site. he will see a button say “click”. when he clicks that button, in the wix database Slot field value (corresponding to his mail id) should become green. I am maintaining his mail id abc@gmail.com manually in my database.

  2. Once the Slot value is set to green how i can read that value using wix code in different page.

If you can provide any sample code for above two cases, it will be of great help. My database name is ParkingDB.

Thanks!

  1. You can see how to save custom data for a user in the article: How to Build Your Own Members Area Using Code . In your case, you will just need one field Slot .

  2. You access the database collection from any page you want. Something like this:

import wixData from 'wix-data';

$w.onReady(function () {
    wixData.query("ParkingDB")    
    .eq("userEmail", "abc@gmail.com")    
    .find()     
    .then( (results) => {
         // found the user's record
         let row = results.items[0]; // get the row from the array
         let slot = row.slot;    // get the slot field
    } );
} );

See the documentation about database collections for more information.