-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
106 lines (91 loc) · 3.23 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<label for="">Username</label>
<input type="text" value="" id="username" />
<label for="">email</label>
<input type="email" value="" id="email" />
<input type="submit" value="submit" id="submit" />
<button id="deletedb">Delete</button>
<p id="pp"></p>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.8.1/firebase-app.js";
// TODO: Add SDKs for Firebase products that you want to use
import {
getDatabase,
ref,
set,
get,
remove,
child,
} from "https://www.gstatic.com/firebasejs/10.8.1/firebase-database.js";
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBZLaW7t69M--gyyZgO_mQxg7z7CAoUcHE",
authDomain: "creativetutorial-e98d0.firebaseapp.com",
projectId: "creativetutorial-e98d0",
storageBucket: "creativetutorial-e98d0.appspot.com",
messagingSenderId: "446775683086",
appId: "1:446775683086:web:f492ee43757d251f01f45f",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
var database = getDatabase();
document.getElementById("submit").addEventListener("click", function (e) {
let username = document.getElementById("username").value;
let email = document.getElementById("email").value;
set(ref(database, "userrrr/" + username), {
username: username,
email: email,
});
alert("stored");
});
///// geting data from firebase
function show() {
const dbref = ref(database);
get(child(dbref, "userrrr/")).then((snapshot) => {
let darray = [];
snapshot.forEach((childSnapshot) => {
darray.push(childSnapshot.val());
});
gooo(darray);
});
}
show();
let ht = "";
function gooo(darray) {
darray.map((e, i) => {
ht += `<p>User name : ${e.username} \n Email ID :${e.email} </p>`;
});
document.getElementById("pp").innerHTML = ht;
}
/// deleteing data from firebase
function deletedb() {
let username = document.getElementById("username").value;
const dbref = ref(database);
remove(ref(dbref, "userrrr/" + username))
.then(() => {
alert("deleted");
})
.catch((error) => {
alert("error");
});
}
document
.getElementById("deletedb")
.addEventListener("click", function () {
let username = document.getElementById("username").value;
let email = document.getElementById("email").value;
remove(ref(database, "userrrr/" + username));
alert("deleted");
});
</script>
</body>
</html>