-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud.html
126 lines (120 loc) · 4.29 KB
/
crud.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
label{
display: block;
width: 80px;
}
input,select{
width:120px;
}
</style>
</head>
<body>
<label>Name</label><input id="Namebox" type="text">
<label>RollNo</label><input id="Rollbox" type="text">
<label>Section</label><input id="Secbox" type="text">
<label>Gender</label>
<select id="Genbox">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
<hr>
<button id="Insbtn">INSERT</button>
<button id="Selbtn">SELECT</button>
<button id="Updbtn">UPDATE</button>
<button id="Delbtn">DELETE</button>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.7/firebase-app.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyDoPQfGPO1hPMzkqxZAcSsHHKAMjEM_ReU",
authDomain: "fire9db-1a344.firebaseapp.com",
projectId: "fire9db-1a344",
storageBucket: "fire9db-1a344.appspot.com",
messagingSenderId: "432192363727",
appId: "1:432192363727:web:5ac78fba3cf3d052796bba"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
import{getDatabase,ref,set,get,child,update,remove}
from "https://www.gstatic.com/firebasejs/9.6.7/firebase-database.js";
const db=getDatabase();
var namebox=document.getElementById("Namebox");
var rollbox=document.getElementById("Rollbox");
var secbox=document.getElementById("Secbox");
var genbox=document.getElementById("Genbox");
var insBtn=document.getElementById("Insbtn");
var selBtn=document.getElementById("Selbtn");
var updBtn=document.getElementById("Updbtn");
var delBtn=document.getElementById("Delbtn");
//insert data function
function InsertData(){
set(ref(db,"TheStudents/"+rollbox.value),{
NameOfStd:namebox.value,
RollNo:rollbox.value,
Section:secbox.value,
Gender:genbox.value
})
.then(()=>{
alert("data stored successfully");
})
.catch((error)=>{
alert("unsuccessful,error"+error);
});
}
//select data function
function SelectData(){
const dbref=ref(db);
get(child(dbref,"TheStudents/"+rollbox.value)).then((snapshot)=>{
if(snapshot.exists()){
namebox.value=snapshot.val().NameOfStd;
secbox.value=snapshot.val().Section;
genbox.value=snapshot.val().Gender;
}
else{
alert("No data found");
}
})
.catch((error)=>{
alert("unsuccessful,error"+error);
})
}
//update data
function UpdateData(){
update(ref(db,"TheStudents/"+rollbox.value),{
NameOfStd:namebox.value,
Section:secbox.value,
Gender:genbox.value
})
.then(()=>{
alert("data updated successfully");
})
.catch((error)=>{
alert("unsuccessful,error"+error);
});
}
function DeleteData(){
remove(ref(db,"TheStudents/"+rollbox.value))
.then(()=>{
alert("data removed successfully");
})
.catch((error)=>{
alert("unsuccessful,error"+error);
});
}
insBtn.addEventListener('click',InsertData)
selBtn.addEventListener('click',SelectData)
updBtn.addEventListener('click',UpdateData)
delBtn.addEventListener('click',DeleteData)
</script>
</body>
</html>