-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.html
86 lines (68 loc) · 2.55 KB
/
data.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
<html>
<head>
<title>Database Test</title>
</head>
<body>
<label for="email">Email</label>
<input id="email" name="email" type="text" placeholder="Enter Email">
<label for="uname">Username</label>
<input id="uname" type="text" placeholder="Enter Username" name="uname">
<label for="age">Age</label>
<input id="age" type="text" placeholder="Enter Age" name="age">
<button type="submit" id="submitData">SUBMIT</button>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.18.0/firebase-app.js";
import { getDatabase, ref, set, onValue, update, remove } from "https://www.gstatic.com/firebasejs/9.18.0/firebase-database.js";
const firebaseConfig = {
apiKey: "AIzaSyDxRbz9F8QBPzokNm0Hl_uxYHMhukCFXj8",
authDomain: "keprinstech-data.firebaseapp.com",
projectId: "keprinstech-data",
storageBucket: "keprinstech-data.appspot.com",
messagingSenderId: "17047244544",
appId: "1:17047244544:web:8c6c3ca4cdf15414bcade5"
};
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
submitData.addEventListener('click',(e) => {
var email = document.getElementById('email').value;
var username = document.getElementById('uname').value;
var age = document.getElementById('age').value;
// const newKey = push(child(ref(database), 'users')).key;
// set(ref(database, 'users/' + username), {
// username: username,
// email: email,
// age : age
// }).then(() => {
// // Data saved successfully!
// alert('data submitted');
// })
// .catch((error) => {
// // The write failed...
// alert(error);
// });
// const starCountRef = ref(database, 'users/' + username);
// onValue(starCountRef, (snapshot) => {
// const data = snapshot.val();
// alert(data.email);
// });
// update(ref(database, 'users/' + username), {
// email: email,
// age : age
// }).then(() => {
// // Data saved successfully!
// alert('data updated');
// })
// .catch((error) => {
// // The write failed...
// alert(error);
// });
// removeData.addEventListener('click',(e) => {
// const username = document.getElementById('username').value;
//
// remove(ref(database, 'users/' + username));
// alert('removed');
// });
});
</script>
</body>
</html>