简体   繁体   English

无法通过网络应用将数据保存在Firebase中

[英]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. 我正在尝试将用户的详细信息保存在Firebase中,因为他进入网站进行注册请求,但该详细信息未保存。 Here is the html code: 这是html代码:

 <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: 使用的相应的javascript是:

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. Firebase在他们的网站上有一个很棒的文档 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/');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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