我已经编写了一些函数来从我的html表单触发到数据库。目的是存储数据并在更新后查看。 ID已插入html。我认为功能存在问题或实时数据库规则错误。我将在下面包含所有代码。我明天要提交作业。我只需要做CRUD功能。谢谢!
<form class="form-horizontal" id="editProfileForm">
<div class="form-group">
<label class="col-lg-3 control-label">Name:</label>
<div class="col-lg-8">
<input class="form-control" type="text" id="name" placeholder="Bishop">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Gender:</label>
<div class="col-lg-2">
<input type="radio" name="gender" id="Gender" value="male">Male<br>
<input type="radio" name="gender" id="Gender" value="female">Female
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Course:</label>
<div class="col-lg-8">
<input class="form-control" type="text" id="Course" placeholder="Information Business">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Faculty:</label>
<div class="col-lg-8">
<input class="form-control" type="text" id="Faculty" placeholder="FICT/ FAS/ FBF and etc...">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Phone number:</label>
<div class="col-lg-8">
<input class="form-control" type="tel" id="Ephone" pattern="[0-9]{3}-[0-9]{3}\[0-9]{4}"
placeholder="999-999 9999">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">University email:</label>
<div class="col-lg-8">
<input class="form-control" type="text" id="email" placeholder="janesemail@gmail.com">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Password:</label>
<div class="col-md-8">
<input class="form-control" type="password" id="Epassword" placeholder="11111122333">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-2">
<input type="submit" class="btn btn-primary" value="Save Changes">
<span></span>
<input type="reset" class="btn btn-default" value="Cancel">
</div>
</div>
</form>
var name;
var gender;
var course;
var faculty;
var phone_num;
var email;
var password;
firebase.auth().onAuthStateChanged(firebaseUser => {
$("#editProfileForm").submit(function(event){
var obj=new Object();
obj.Name=$("#Name").val();
obj.gen=$("#Gender").val();
obj.coursse=$("#Course").val();
obj.fac=$("#Faculty").val();
obj.mail = $("#Eemail").val();
obj.phone = $("#Ephone").val();
obj.home = $("#Eaddress").val();
obj.pass = password;
var insert = {};
insert["/User/"+firebaseUser.uid] = obj;
firebase.database().ref().update(insert);
});
var databaseRef=firebase.database().ref("/User/"+firebaseUser.uid);
databaseRef.once('value').then(function(data)
{
name = data.val().Name;
gender = data.val().gen;
course = data.val().coursse;
faculty = data.val().fac;
email = data.val().mail;
password = data.val().pass;
phone_num = data.val().phone;
$("#Name").val(name);
$("#Gender").val(gender);
$("#Course").val(course);
$("#Faculty").val(faculty);
$("#Eemail").val(email);
$("#Ephone").val(phone_num);
$("#Epassword").val(password);
});
});