-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
117 lines (114 loc) · 5.23 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
session_start();
if($_SESSION["userLogin"]) {
if ($_SESSION["userRole"] === 'employee') header("Location: employeeData.php?id=".$_SESSION['userId']);
} else {
header("Location: login.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
require 'db.php';
if( isset( $_POST['insert'] ) ) {
$did = $_POST['id'];
$sql = "DELETE FROM employeeData WHERE id=$did";
if (mysqli_query($conn, $sql)) {
echo '<script>alert("Record deleted successfully !")</script>';
echo '<script>window.location.reload();)</script>';
} else {
echo "Error deleting record: " . mysqli_error($conn);
}
}
if (isset($_POST['logout'])) {
session_unset();
session_destroy();
header("Location: login.php");
}
?>
<div class='card'>
<div class='d-flex justify-content-between my-3'>
<h4 class='d-flex align-items-center mb-0'>Admin Dashboard</h4>
<div class='d-flex'>
<div class='mr-2'>
<button type="button" class='btn btn-success' onClick="window.location.href='AddRecord.php'">Add Record</button>
</div>
<div>
<form method="post">
<input type="submit" role='button' class='btn btn-danger' name="logout" value="Logout">
</form>
</div>
</div>
</div>
<div>
<table class="table">
<thead class='thead-light'>
<tr>
<th>#</th>
<th>Name</th>
<th>LastName</th>
<th>Email</th>
<th>Gender</th>
<th>Occuption</th>
<th>Hobby</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
require 'db.php';
$sql = "SELECT * FROM employeeData";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['firstname'];?></td>
<td><?php echo $row['lastname'];?></td>
<td><?php echo $row['email'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['occuption'];?></td>
<td>
<?php
$arr = json_decode($row['hobby']);
echo implode(", ",$arr);
?>
</td>
<td>
<div class='d-flex'>
<div class='mr-2'>
<a class='btn btn-primary btn-sm' role="button" name="update" href="<?php echo "AddRecord.php?id=".$row['id'] ?>">Edit</a>
</div>
<div>
<form method='POST'>
<input type=hidden name=id value="<?php echo $row['id'] ?>" >
<input type="submit" class='btn btn-danger btn-sm' role="button" name="insert" value="Delete" />
</form>
</div>
</div>
</td>
</tr>
<?php
}
} else {
echo "<tr><td>No Record found</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</body>
</html>