I followed along with a Firebase Web Tutorial on YouTube about adding data to Firebase Database for an account settings tutorial. However, when I tried to implement the code provided, it didn't work. Can anyone offer any assistance?
// Code snippet for updating user info
$("#btn-update").click(function(){
var fName = $("#fname").val();
var sName = $("#sname").val();
var uName = $("#uname").val();
var country = $("#country").val();
var phone = $("#phone").val();
var gender = $("#gender").val();
var rootRef = firebase.database().ref().child("Users");
var userID = firebase.auth().currentUser.uid;
var usersRef = rootRef.child(userID);
if(fName != "" && sName != "" && uName != "" && country != "" && phone != "" && gender != ""){
var userData = {
"firstName": fName,
"secoundName": sName,
"userName": uName,
"country": country,
"phone": phone,
"gender": gender,
};
usersRef.set(userData, function(){
if(error){
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode);
console.log(errorMessage);
window.alert("Message : " + errorMessage);
}else{
window.location.href="post.html";
}
});
}else{
window.alert("Form is incomplete.! Please fill out all fields.");
}
});