Saving information into the database

My app uses a login system with an email, password, and a profile picture. The email and password is being stored but I want to make it so that the profile picture they chose will be saved under that account. I also want to save more information like journal entries under the account. How would I be able to save such information in the database under the user’s account?

I believe you would use ‘Cloud variables’. This video explains how to set them up:

Thanks for the video. Where can I see the information being stored? How do I save the email, password, and profile picture under the User ID? Is the User ID always going to be the same for the same account?

1 Like

I am not at my computer at the moment so I can’t show you blocks but I believe you need to use the ‘Firebase Realtime DB’. You will need to insert the database URL for that. As for user ID, if you set up authentication on Firbase, when users make an account, you will be able to see their email, username, ID etc.

You’ll want to use a Firebase database. You can refer to Firebase nodes/properties with cloud variable names.

Start here:

Hello! I have a Firebase database. I also have Cloudinary to save images. What I don’t understand is how I can connect the two. My login system with Firebase works great, but I am having trouble with saving the image to the account.

This is my app so far: Thunkable
I noticed that if I sign up and choose an image, it will make the profile image in the home_screen that image for every account. For example, when I run the app, if I already have an account and didn’t need to sign up, it would just show the black profile icon in the home_screen. If I run the app and create a new account, the image that I choose for when I created this account will show up in the home_screen, which is what I want, but when I log out and log in to a different account, the same image is still there.

When you upload an image to Cloudinary (either manually or from Thunkable blocks), it generates a url for the image. You can then add that url to Firebase.

1 Like

Can you show me what code I need to do for that? I don’t know what kind of variable to store it as and how to add the url to Firebase.

If you Google Cloudinary Thunkable, the first result should be the documentation for using Cloudinary which includes set up, a video, etc.

Look for the “Upload Media” section of the documentation. Once you generate the green mediaURL block, you can save its value to Firebase. To see what Firebase access using cloud variable names looks like, check out this example:

It took me hours to get this all working. It’s definitely possible but it does take some time to set up and test and troubleshoot.

1 Like

Ok, thank you very much for your help. I have one more question. The User ID is an app variable, the email and password is a stored variable, and the image is a cloud variable, correct?

Any variables that you want to store in Firebase need to be cloud variables. So that would be all of them. But as you work with them in Thunkable, you may prefer to assign them to app variables in order speed things up a little. You don’t have to do that. As far as stored variables go, that’s for anything you want saved on the user’s device.

2 Likes

I’m stumped. I’m still trying to solve this problem but data won’t save into the database. Please take a look at my screenshots. Is there anything I’m doing wrong??



You have a lot going on. What happens if you separate out the steps? For example:

  1. Are you able to select a photo and generate a (green block) url from Cloudinary? If you view that url in a browser does it show the photo you selected?
  2. Are you able to change ANY data in Firebase? For example, can you update something simple like a text string?

Hi, I checked to make sure everything works. The ones with the stars work for sure but the ones that I squared out seem to have an issue. I’m not able to add or change any data in Firebase.

I don’t understand the establishing the data function at all. I don’t see why you would want to set the userEmail value to anything at that point. Plus, you don’t generally need to check to see if cloud variables are null. That’s really for stored variables.

I would try removing the establishing the data function call from the when signup_screen Opens block and see if that helps. Also check to see what the value of stored variable userEmail + “/image URL” is by setting a label to that value.

Can Firebase nodes have spaces in their names? I don’t think so. Try changing “/image URL” to “/imageURL”.

Hi. I removed the establish the data function. I also set up a new database for this app and checked to make sure it works. It works, but I found that the issue is in cloud variable join stored variable userEmail + "/imageURL". I removed the space like you said, thank you for catching that. But, it still does not work. I don’t know how to set a label to that value… How can I do that?

I realized what else seems a little unusual about what you’re doing. I use the green userId block in the Sign In block as the Firebase node name. You’re using the email address. I don’t know if the ‘@’ symbol would cause a problem but it’s possible. Maybe it’s okay to use an email address but you might try the userId that Thunkable generates.

I also recommend not trying everything at once. You’re still choosing an image, uploading it to Cloudinary, generating a media url, signing up/in to Firebase, changing a Firebase node value… which means that there are soooo many variables for what could go wrong. I don’t mean variables in the programming sense, I mean it in the scientific experiment sense. You need a control. And then one variable that may change. Simplify things so that, for example, you’re using a static value for the cloud variable. Not the email, not a userId… just something like “Bob”. And then you see if you can update Bob/ImageURL with something simple like “test.jpg”. Can you get that to work?

1 Like

I got it to work! I think you’re right that the issue is with the stored variable userEmail. I think I might set it to the password instead. I tried doing the User ID, but I call that variable after the user logs in so unfortunately it just says “null” with the image URL under it inside the database. Hopefully setting the cloud variable as the password doesn’t cause an issue. Thank you so much for you help!! :smiley:

You’re welcome. I’m glad you’re getting parts of it to work. I don’t think it’s a good idea to choose the password as the node name. It’s pretty likely that two people might choose the same password and then you have a real problem.