简体   繁体   中英

Not able to save data in firebase from web app

I am trying to save the details of user in the firebase as he enters in the website for sign up request but the details are not saving. Here is the html code:

 <input type="name" placeholder="Full Name..." id="name_field1" class="inp" />
                                 <input type="email" placeholder="Email..." id="email_field1" class="inp" />
<input type="text" placeholder="Desired Password..." id="password_field1" class="inp" />
<button onclick="save()">Request Sign In</button>

The corresponding javascript used is:

var name=document.getElementById("name_field1");
var email=document.getElementById("email_field1");
var pass=document.getElementById("password_field1");
function save(){

var firebaseRef=firebase.database().ref();
var nam=comm.value;
var em=email.value;
var pas=pass.value;
firebaseRef.push().set(nam);
firebaseRef.push().set(em);
firebaseRef.push().set(pas);

}

you need to push values:

firebaseRef.push(nam);
firebaseRef.push(em);
firebaseRef.push(pas);

Firebase has an amazing documentation on their website. I bet you'd master it within weeks if you read an article everyday.

Initialize your DB first:

// Get a reference to the database service
var database = firebase.database();

Write the data:

database.ref('users/ashley').set({
    username: value1,
    email: value2,
    profile_picture : value3
});

Also. Please don't save user passwords in the DB

不要将ref()留空。尝试以下方法:

var firebaseRef=firebase.database().ref('testKey/');

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