-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_members.php
More file actions
141 lines (124 loc) · 4.71 KB
/
Copy pathview_members.php
File metadata and controls
141 lines (124 loc) · 4.71 KB
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
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (!isset($_SESSION['username'])) {
header("Location: login1.php"); // Redirect to login page if not logged in
exit();
}
include 'db_connection.php';
// ✅ Search Query Logic
$search = "";
if (isset($_GET['search'])) {
$search = mysqli_real_escape_string($conn, $_GET['search']);
$query = "SELECT * FROM students WHERE student_id LIKE '%$search%' OR name LIKE '%$search%'";
} else {
$query = "SELECT * FROM students"; // Default: Fetch all students
}
$result = mysqli_query($conn, $query);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View All Members</title>
<!-- SweetAlert2 CDN -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<style>
body { font-family: Arial, sans-serif; text-align: center; }
table { width: 80%; margin: 20px auto; border-collapse: collapse; }
th, td { padding: 10px; border: 1px solid black; text-align: center; }
th { background-color: #007bff; color: white; }
.delete-btn { color: white; background-color: red; padding: 5px 10px; text-decoration: none; border-radius: 5px; border:none; cursor: pointer; }
.delete-btn:hover { background-color: darkred; }
.back-btn { display: block; text-align: center; margin-top: 20px; font-size: 18px; text-decoration: none; color: white; background: #ff4b4b; padding: 10px; border-radius: 5px; width: 200px; margin: auto; }
.back-btn:hover { background: darkred; }
.search-box { margin-bottom: 20px; }
.search-input { padding: 10px; width: 250px; border: 1px solid #ccc; border-radius: 5px; }
.search-btn { padding: 10px 15px; background: #007bff; color: white; border: none; cursor: pointer; border-radius: 5px; }
.search-btn:hover { background: #0056b3; }
.edit-btn {
color: white;
background-color: #28a745;
padding: 5px 10px;
text-decoration: none;
border-radius: 5px;
cursor: pointer;
border: none;
font-size: 16px;
}
.edit-btn:hover {
background-color: #218838;
}
</style>
</head>
<body>
<h2>Displaying All Members</h2>
<!-- ✅ Search Form -->
<form method="GET" action="view_members.php" class="search-box">
<input type="text" name="search" class="search-input" placeholder="Search by Student ID or Name" value="<?= htmlspecialchars($search) ?>">
<button type="submit" class="search-btn">Search</button>
</form>
<!-- ✅ Success & Error Messages from Session -->
<?php if (isset($_SESSION['success_message'])) { ?>
<script>
Swal.fire({
title: "Success!",
text: "<?= $_SESSION['success_message'] ?>",
icon: "success",
confirmButtonText: "OK"
});
</script>
<?php unset($_SESSION['success_message']); // ✅ Session Message Clear Karna Zaroori Hai ?>
<?php } ?>
<?php if (isset($_SESSION['error_message'])) { ?>
<script>
Swal.fire({
title: "Error!",
text: "<?= $_SESSION['error_message'] ?>",
icon: "error",
confirmButtonText: "OK"
});
</script>
<?php unset($_SESSION['error_message']); ?>
<?php } ?>
<table>
<tr>
<th>Student ID</th>
<th>Name</th>
<th>Department</th>
<th>Action</th>
</tr>
<?php while ($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?= $row['student_id'] ?></td>
<td><?= $row['name'] ?></td>
<td><?= $row['department'] ?></td>
<td>
<button class="edit-btn" onclick="window.location.href='edit_member.php?id=<?= $row['student_id'] ?>'">Edit</button>
<button class="delete-btn" onclick="confirmDelete(<?= $row['student_id'] ?>)">Delete</button>
</td>
</tr>
<?php } ?>
</table>
<a href="admin_dashboard.php" class="back-btn">⬅ Back to Dashboard</a>
<script>
function confirmDelete(studentId) {
Swal.fire({
title: "Are you sure?",
text: "You won't be able to revert this!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#3085d6",
confirmButtonText: "Yes, delete it!"
}).then((result) => {
if (result.isConfirmed) {
window.location.href = "delete_member.php?id=" + studentId;
}
});
}
</script>
</body>
</html>