简体   繁体   中英

Retrieve data from firebase realtime database and auto fill into textbox

I want to retrieve the data from firebase real time database, and auto fill it up with the data inside the database which the user had already key in once they sign up. I saved the user data under their UID , now I have a problem for retrieving the data from the database by their UID and auto fill for the user by current login user uid.

My Firebase database https://imgur.com/a/BlzFADs

The places to be auto-filled https://imgur.com/a/urvNAFe

I tried all possible solutions for my code, but i cant seem to make it work, all solutions i found on stackoverflow, but still it doesnt work for me.

 firebase.database().ref('Users/User Information').child(uid).once('value', 
 function(snapshot) {

   document.getElementById('name').value = snapshot.child("Name").val();
 });

 <td>Name:</td>
 <td>
     <input type="text" id="name" name="name" style="font-size:10pt; width:200px;" placeholder="Enter Name Here" required>
 </td>  

Now I want to fill the data for the current logged in user automatically based on their UID.

Try below code:

firebase.database().ref('Users/User Information/'+uid.value).once('value', 
 function(snapshot) {
   document.getElementById('name').value = snapshot.val().Name;
});

Or this with arrow function:

firebase.database().ref('Users/User Information/'+uid.value).once('value', (snapshot) => 
{
  document.getElementById('name').value = snapshot.val().Name;
});

我通过使用 document.getelementbyID 完成此操作,并将其链接到数据库的子项。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM