Create and Save Data in Firebase

Hi there,

I made an apps for school and I need to save data in firebase but when I did my block, the data doesn’t showed up in firebase. Its doesn’t upload. Am I doing it wrong ?

It looks like that should work.

Try this:

  1. Set a label’s text to these blocks and tell us what you see when you do that:

image

That will confirm that the cloud variable path is correct.

  1. Try a simple Firebase save by setting cloud variable [join] [app variable userId] [“/test”] to “this is a test”

Check your Firebase realtime database and let us know if “this is a test” shows up for that user under the “test” key.

That will confirm that you can write to Firebase.

I’m sorry but can you explain it in more detail ? I don’t really understand what you meant by the 2 point that you said.

When you try something complicated in Thunkable and it doesn’t work, the best thing to do is to try the simplest form of it you can and see what happens. If that doesn’t work then the more complicated thing won’t work.

So I’m suggesting that you modify these blocks:

Another way to do this is to remove the [convertemailToId] block from the join block and then set the cloud variable to a text string (instead of an object).

Does any data change in Firebase when you try this?

no, nothing change.

Did you mean like this?

Screenshot 2023-01-15 012429

Does the database location give effects to it ?

Yes.

Then either your Firebase authentication settings in Thunkable are not correct or your rules in the Firebase console are not correct. See this: Realtime DB by Firebase - Thunkable Docs

I don’t know what you mean.

I did it, but the things is whenever I tried to key in another data, it will change the previous data into a new one. I don’t want it to change the previous data into a new one cause I would like to save all the data. Whats the problem here ?

If you set cloud variable [app variable userId]/path to a value, it replaces all data below that path. It doesn’t make sense to use a path like [app variable userId]/users because the userId should be the unique key within the path. You wouldn’t want multiple users under [app variable userId]/. So a better approach is to organize Firebase like this:

Users/
   [userID]

Where you keep adding userIDs below Users/ like this:

Users/
   sjfh327857343
   oight2y982351
   kashjfsgd2314

And inside of each [userId] key you can have paths to objects or values:

Users/
   sjfh327857343/
      fullname
      NRIC
   oight2y982351/
      fullname
      NRIC
   kashjfsgd2314/
      fullname
      NRIC
1 Like

Thank you, now I already got it !

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.