我一直在注册页面上工作,我的数据没有存储到数据库中。代码在下面。不存在控制台错误。我已经尝试了很多不同的想法,我只是想存储数据。另外,另一个问题,是否有方法检查数据库中的两个值是否在同一电子邮件下?我想知道这是一个密码系统。能帮帮我吗我真的很沮丧,希望这能奏效。
<button type="button" id="signUpButton" onclick="confirmData() ; stopClicksAgain()">Sign Up!</button>
<script type="module" src="backend/database.js/"><script>
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-app.js";
import { getDatabase, ref, set } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-database.js";
const firebaseConfig = {
apiKey: "AIzaSyDJdI7Sgr7ZGo3Do6NVswgs1UvjVcQUZbs",
authDomain: "bakerstoolbox-9ca91.firebaseapp.com",
databaseURL: "https://bakerstoolbox-9ca91-default-rtdb.firebaseio.com",
projectId: "bakerstoolbox-9ca91",
storageBucket: "bakerstoolbox-9ca91.appspot.com",
messagingSenderId: "175444196196",
appId: "1:175444196196:web:f6314c643c71315b5f1871"
};
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
//get user sign up data
var email = document.getElementById("email");
var phone = document.getElementById("phone-number");
var firstName = document.getElementById("firstName");
var lastName = document.getElementById("lastName");
//button functions
const signUpButton = document.getElementById("signUpButton");
signUpButton.addEventListener("click", signUpNewUser);
//sign up a new user
function signUpNewUser(){
set(ref(database, 'users/'), {
userEmail : email,
userPhoneNum : phone,
userFirstName : firstName,
userLastName : lastName
})
.then(() => {
console.log("GOOD")
})
.catch((error) => {
console.log("ERROR")
});
}
1条答案
按热度按时间nukf8bse1#
当你运行这段代码时:
你得到的是一个HTML元素,而不是用户输入到该字段中的值。要获取后者,通常需要读取其
value
属性。参见How can I get HTML element value by JavaScript?