-
Notifications
You must be signed in to change notification settings - Fork 2
/
notes.php
226 lines (196 loc) · 8.97 KB
/
notes.php
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
<?php
$db = mysqli_connect('localhost', 'root', '', 'notes') or die("Could not connect to Database");
$insert = false;
?>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- <link rel="stylesheet" href="//cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css.css"> -->
<link href="https://fonts.googleapis.com/css2?family=Merriweather:wght@400;700&display=swap" rel="stylesheet">
<style>
body {
/* font-family: 'Merriweather', serif; */
font-size: 17px;
}
</style>
<title>iNotes - The notes taking app</title>
</head>
<body>
<!-- Modal start -->
<!-- Button trigger modal
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
Launch demo modal
</button> -->
<!-- Modal -->
<div class="modal fade" id="edit_modal_id" role="dialog" tabindex="-1" aria-labelledby="edit_modal_idLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Edit Note</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="" method="post">
<input type="hidden" name="snoEdit" id="snoEdit">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Title</label>
<input type="text" class="form-control" id="title_edit_id" placeholder="Title" name="title_edit_name">
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">Description</label>
<textarea class="form-control" id="desc_edit_id" rows="3" placeholder="Description" name="desc_edit_name"></textarea>
</div>
<input type="submit" name="update_note_name" class="btn btn-primary" value="Update note"></input>
</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>
<!-- Modal end -->
<!-- navbar start -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">iNotes</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
<!-- Search bar start -->
<form class="d-flex" action="" method="post">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" name="searchitems_name" autocomplete="off">
<button class="btn btn-outline-success" type="submit" name="search_name">Search</button>
</form>
<!-- Search bar end -->
</div>
</div>
</nav>
<!-- navbar end -->
<div class="container my-4">
<h2 class="my-3">Add Notes Here</h2>
<!-- input area start -->
<form action="" method="post">
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">Title</label>
<input type="text" class="form-control" id="exampleFormControlInput1" placeholder="Title" name="title_name">
</div>
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">Description</label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" placeholder="Description" name="desc_name"></textarea>
</div>
<input type="submit" name="add_note_name" class="btn btn-primary" value="Add note"></input>
</form>
<!-- input area end -->
</div>
<div class="container my-4">
<!-- table start -->
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Sl no.</th>
<th scope="col">Title</th>
<th scope="col">Description</th>
<th scope="col">Action</th>
</tr>
</thead>
<?php
// Inserting into database table start
if (isset($_POST['add_note_name'])) {
$a = $_POST['title_name'];
$b = $_POST['desc_name'];
$query = "INSERT into note_s(title, description) VALUES('$a', '$b')";
$result = mysqli_query($db, $query) or die("Could not execute querry");
if ($result) {
$insert = true;
}
// else{
// echo("Could not insert");
// }
}
// Inserting into database table end
//update data inserting to database start
if (isset($_POST['update_note_name'])) {
$a = $_POST['title_edit_name'];
$b = $_POST['desc_edit_name'];
$c = $_POST['snoEdit'];
$query = "UPDATE note_s SET title = '$a', description = '$b' WHERE sl_no = $c";
$result = mysqli_query($db, $query) or die("Could not execute querry");
if ($result) {
$insert = true;
}
}
//update data inserting to database end
$v = 1;
//display on search start
if (isset($_POST['search_name'])) {
$c = $_POST['searchitems_name'];
$query = "SELECT * FROM note_s WHERE title like '%" . $c . "%' OR description like '%" . $c . "%'";
$result = mysqli_query($db, $query) or die("Cannot find any matches");
while ($row = mysqli_fetch_row($result)) {
echo ("<tbody>
<tr>
<th scope='row'>$v</th>
<td>$row[1]</td>
<td>$row[2]</td>
<td><button class='edit btn btn-sm btn-danger' id='$v' name='edit_name'>Edit</button>
<button class='btn btn-sm btn-success my-1' onclick='deleteit(" . $row[0] . ")'>Delete</button></td>
</tr>
</tbody>");
$v++;
}
}
//display on search end
$v = 1;
//displaying into table start
if (!(isset($_POST['search_name']))) {
$query = "SELECT * FROM note_s";
$result = mysqli_query($db, $query) or die("Could not execute querry");
while ($row = mysqli_fetch_row($result)) {
echo ("<tbody>
<tr>
<th scope='row'>$v</th>
<td>$row[1]</td>
<td>$row[2]</td>
<td><button class='edit btn btn-sm btn-danger' id='$v' name='edit_name'>Edit</button>
<button class='btn btn-sm btn-success my-1' onclick='deleteit(" . $row[0] . ")'>Delete</button></td>
</tr>
</tbody>");
$v++;
}
}
//displaying into table end
?>
</table>
<!-- table end -->
</div>
<script src="notes.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.10.2/dist/umd/popper.min.js" integrity="sha384-7+zCNj/IqJ95wo16oMtfsKbZ9ccEh31eOz1HGyDuCQ6wgnyJNSYdrPa03rtR1zdB" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.min.js" integrity="sha384-QJHtvGhmr9XOIpI6YVutG+2QOK9T+ZnN4kzFN1RtK3zEFEIsxhlmWl5/YESvpZ13" crossorigin="anonymous"></script>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!-- Option 2: Separate Popper and Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
<!-- <script src="//cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script> -->
<!-- <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script> -->
</body>
</html>