-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
273 lines (225 loc) · 9.64 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
$servername="localhost";
$username="root";
$pasword="";
$dbname="notes";
$conn =mysqli_connect($servername,$username,$pasword,$dbname);
if(!$conn)
{
die("Sorry we failed to connect: ".mysqli_connect_error());
}
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if($_GET['key']=='update')
{
$sn=$_POST['sn_edit'];
$title= $_POST['title_edit'];
$des=$_POST['note_edit'];
$sql="UPDATE `notes` SET `Title`='$title' ,`Des`='$des' WHERE `Title`='$sn'";
$result=mysqli_query($conn,$sql);
}
if($_GET['key']=='insert')
{
$title= $_POST['title'];
$des=$_POST['note'];
$sql="INSERT INTO `notes` (`Title`,`Des`) VALUES ('$title','$des')";
$result=mysqli_query($conn,$sql);
}
if($_GET['key']=='delete')
{
$title= $_POST['sn_dele'];
$sql="DELETE FROM `notes` WHERE `title`='$title'";
$result=mysqli_query($conn,$sql);
}
}
// mysqli_close($conn);
?>
<!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>Notes</title>
</head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<style>
#out{
background-color: rgba(128, 128, 128, 0.475);
box-shadow: 0 0 5px black;
width: 400px;
}
body::-webkit-scrollbar
{
background-color:white;
}
body::-webkit-scrollbar-thumb
{
background-color:rgb(7, 101, 209);
border-radius: 20px;
}
</style>
<link rel="stylesheet" href="//cdn.datatables.net/1.13.1/css/jquery.dataTables.min.css">
<body>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Edit Note</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="http://localhost/cruwd.php/cruwd.php?key=update" method="post">
<div class="form-group">
<input type="text" style="display:none;" name="sn_edit" id="sn_edit">
<label for="title_edit">Enter Title</label>
<input type="text" class="form-control" id="title_edit" name="title_edit" aria-describedby="emailHelp" placeholder="Enter Tiltle" >
<!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
</div>
<div class="form-group">
<label for="note_edit">Write note</label> <br>
<textarea name="note_edit" id="note_edit" cols="45" rows="5" class="form-control" placeholder="Write here..."></textarea>
</div>
<button type="submit" class="btn btn-primary my-4">Update note</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<!-- dele modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="http://localhost/cruwd.php/cruwd.php?key=delete" method="post">
<input type="text" style="display:none;" name="sn_dele" id="sn_dele">
<span>ARE you sure?</span>
<button type="submit" class="btn btn-primary my-4" >OK</button>
</form>
</div>
</div>
</div>
</div>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Note Pad</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
</div>
</nav>
<div class="container my-5" id="out">
<form action="http://localhost/cruwd.php/cruwd.php?key=insert" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Enter Title</label>
<input type="text" class="form-control" id="title" name="title" aria-describedby="emailHelp" placeholder="Enter Tiltle" >
<!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
</div>
<div class="form-group">
<label for="note">Write note</label> <br>
<textarea name="note" id="note" cols="45" rows="5" class="form-control" placeholder="Write here..."></textarea>
</div>
<button type="submit" class="btn btn-primary my-4">Add note</button>
</form>
</div>
<div class="container">
<table class="Table table" id="myTable">
<thead>
<tr>
<td>Sn</td>
<td class="col">Title</td>
<td class="col">Notes</td>
<td class="col">Actions</td>
</tr>
</thead>
<tbody>
<?php
$sn=1;
$sql="SELECT * FROM `notes`";
$result=mysqli_query($conn,$sql);
while($row=mysqli_fetch_assoc($result))
{
echo "
<tr>
<td>$sn</td>
<td class='title'>".$row['Title']."</td>
<td>".$row['Des']."</td>
<td><button class='btn btn-primary my-4 edit'>"."Edit"."</button><button class='dele btn btn-primary my-4'>"."Delete"."</button></td>
</tr>";
$sn+=1;
}
?>
</tbody>
</table>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script src="https://cdn.datatables.net/1.13.1/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready( function () {
$('#myTable').DataTable();
} );
</script>
<script>
let edits=document.getElementsByClassName("edit")
Array.from(edits).forEach(e => {
e.addEventListener('click',()=>{
// console.log(e.parentElement.parentElement)
let title=e.parentElement.parentElement.getElementsByTagName("td")[2].textContent
let note=e.parentElement.parentElement.getElementsByTagName("td")[3].textContent
let sn=e.parentElement.parentElement.getElementsByTagName("td")[0].textContent
// console.log(title)
sn_edit.value=title
title_edit.value=title //imp
note_edit.value=note //imp
$('#exampleModal').modal('toggle')
})
});
</script>
<script>
let dels=document.getElementsByClassName("dele")
Array.from(dels).forEach(e => {
e.addEventListener('click',()=>{
let title=e.parentElement.parentElement.getElementsByTagName("td")[2].textContent
sn_dele.value=title //imp
console.log(sn_dele.value)
$('#exampleModalCenter').modal('show')
})
});
</script>
<script>
let cls=document.getElementsByClassName("close")
Array.from(cls).forEach(e => {
e.addEventListener('click',()=>{
$('#exampleModalCenter').modal('hide')
$('#exampleModal').modal('hide')
})
});
</script>
</body>
</html>