-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_student.php
123 lines (111 loc) · 4.77 KB
/
edit_student.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
<?php
// This code is used to edit student data in edit_student.php page
include 'database.php';
if (isset($_GET['matric_id'])) {
$matric_id = $_GET['matric_id'];
// Fetch student data based on the matric_id
$sql = "SELECT * FROM student WHERE matric_id='$matric_id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
} else {
echo "No student found with the given Matric ID.";
exit();
}
} else {
echo "Matric ID not provided.";
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Student Details</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!--Header with title and PSSCMUSM logo-->
<header>
<div class="logo">
<img src="images/logo.png" alt="Logo">
</div>
<h1>PSSCMUSM Management System</h1>
</header>
<div class="container">
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="sdm.html" class="active" >Student Data Management</a></li>
<li><a href="test_class.html">Test Result</a></li>
<li><a href="anr.html">Attendance & Records</a></li>
<li><a href="visual.html">Data Visualization</a></li>
</ul>
<button class="logout-btn">Logout</button>
</nav>
</div>
<!-- Navigation text -->
<div class="navigation-text">
Student Data Management > Edit Student Details
</div>
<div class="student-details-container">
<form id="studentForm" enctype="multipart/form-data">
<input type="hidden" name="matric_id" value="<?php echo $row['matric_id']; ?>">
<div class="form-group">
<label for="fullName">Full Name as in IC</label>
<input type="text" id="fullName" name="fullName" value="<?php echo $row['full_name']; ?>" oninput="this.value = this.value.toUpperCase()" required>
</div>
<div class="form-group inline">
<label for="matricID">Matric ID</label>
<input type="text" id="matricID" name="matricID" value="<?php echo $row['matric_id']; ?>" maxlength="10" required readonly>
<label for="gender">Gender</label>
<select id="gender" name="gender" required>
<option value="male" <?php echo ($row['gender'] == 'male') ? 'selected' : ''; ?>>Male</option>
<option value="female" <?php echo ($row['gender'] == 'female') ? 'selected' : ''; ?>>Female</option>
</select>
</div>
<div class="form-group">
<label for="icNumber">IC Number:</label>
<input type="text" id="icNumber" name="icNumber" value="<?php echo $row['ic_number']; ?>" placeholder="Enter IC Number" maxlength="12">
</div>
<div class="form-group">
<label for="school">School</label>
<input type="text" id="school" name="school" value="<?php echo $row['school']; ?>" oninput="this.value = this.value.toUpperCase()" required>
</div>
<div class="form-group">
<label for="image">Image (.png format)</label>
<input type="file" id="image" name="image" accept=".png">
</div>
<button type="submit" class="submit-btn">Update</button>
</form>
</div>
<!--Referring to external JavaScript file-->
<script src="script.js" defer></script>
<script>
// Add event listener to the logout button
document.querySelector('.logout-btn').addEventListener('click', function() {
// Redirect to login.html
window.location.href = 'login.html';
});
// Handle form submission with JavaScript
document.getElementById('studentForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent the default form submission
const formData = new FormData(this);
fetch('process_update.php', {
method: 'POST',
body: formData
})
.then(response => response.text())
.then(result => {
alert('Student details updated successfully!');
window.history.back(); // Redirect to the previous page
})
.catch(error => {
console.error('Error:', error);
alert('An error occurred while updating the student details.');
});
});
</script>
</body>
</html>