-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_student.php
More file actions
56 lines (50 loc) · 1.55 KB
/
view_student.php
File metadata and controls
56 lines (50 loc) · 1.55 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
<?php
include("db_connection.php");
// Delete student if delete_id is set
if(isset($_GET['delete_id'])) {
$delete_id = $_GET['delete_id'];
$delete_sql = "DELETE FROM student WHERE student_id = $delete_id";
if(mysqli_query($conn, $delete_sql)) {
echo "<p style='color:green'>Student deleted successfully!</p>";
} else {
echo "<p style='color:red'>Error: " . mysqli_error($conn) . "</p>";
}
}
// Fetch all students
$result = mysqli_query($conn, "SELECT * FROM student ORDER BY student_id");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Students</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2>All Students</h2>
<table border="1" cellpadding="10">
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Course</th>
<th>Action</th>
</tr>
<?php while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?php echo $row['student_id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['course']; ?></td>
<td>
<a href="view_student.php?delete_id=<?php echo $row['student_id']; ?>"
onclick="return confirm('Are you sure to delete?')">Delete</a>
</td>
</tr>
<?php } ?>
</table>
<br>
<a href="index.php">Back to Home</a>
</body>
</html>