-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.php
100 lines (93 loc) · 3.19 KB
/
index.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
<!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">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<link rel="stylesheet" href="./style.css">
<link rel="shortcut icon" href="./favicon.ico" type="image/x-icon">
<title>PHP CRUD Operations</title>
</head>
<body>
<div class="container">
<div class="py-4">
<a href="./create.php" class="btn btn-secondary">
<i class="bi bi-plus-circle-fill"></i> Add Employee
</a>
</div>
<!-- Table starts here -->
<table class="table table-bordered table-striped align-middle">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>Age</th>
<th>Gender</th>
<th>Role</th>
<th>Joining Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
# Include connection
require_once "./config.php";
# Attempt select query execution
$sql = "SELECT * FROM employees";
if ($result = mysqli_query($link, $sql)) {
if (mysqli_num_rows($result) > 0) {
$rows = mysqli_fetch_all($result, MYSQLI_ASSOC);
$count = 1;
foreach ($rows as $row) { ?>
<tr>
<td><?= $count++; ?></td>
<td><?= $row["first_name"]; ?></td>
<td><?= $row["last_name"]; ?></td>
<td><?= $row["email"]; ?></td>
<td><?= $row["age"]; ?></td>
<td><?= $row["gender"]; ?></td>
<td><?= $row["designation"]; ?></td>
<td><?= $row["joining_date"]; ?></td>
<td>
<a href="./update.php?id=<?= $row["id"]; ?>" class="btn btn-primary btn-sm">
<i class="bi bi-pencil-square"></i>
</a>
<a href="./delete.php?id=<?= $row["id"]; ?>" class="btn btn-danger btn-sm">
<i class="bi bi-trash-fill"></i>
</a>
</td>
</tr>
<?php
}
# Free result set
mysqli_free_result($result);
} else { ?>
<tr>
<td class="text-center text-danger fw-bold" colspan="9">** No records were found **</td>
</tr>
<?php
}
}
# Close connection
mysqli_close($link);
?>
</tbody>
</table>
</div>
<script>
const delBtnEl = document.querySelectorAll(".btn-danger");
delBtnEl.forEach(function(delBtn) {
delBtn.addEventListener("click", function(e) {
const message = confirm("Are you sure you want to delete this record?");
if (message == false) {
e.preventDefault();
}
});
});
</script>
</body>
</html>