-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
186 lines (159 loc) · 5.56 KB
/
edit.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
// Start the session to check user login status
session_start();
// Redirect to login page if not logged in
if (!isset($_SESSION['UserLogin'])) {
header("Location: login.php");
exit();
}
// Include the database connection function
include_once("connections/connection.php");
// Establish a database connection
$con = connection();
// Check if the "Update" button is clicked
if (isset($_POST['update'])) {
$id = $_POST['id'];
$fname = $_POST['firstname'];
$lname = $_POST['lastname'];
$gender = $_POST['gender'];
// Update the record in the database using the provided data
$sql = "UPDATE student_list SET first_name = '$fname', last_name = '$lname', gender = '$gender' WHERE ID = '$id'";
$con->query($sql) or die($con->error);
// Display a success alert
echo '<div class="alert alert-success mt-3" role="alert">
Student details updated successfully!
</div>';
}
// Check if the "Delete" button is clicked
if (isset($_POST['delete'])) {
$id = $_POST['id'];
// Delete the record from the database
$deleteSql = "DELETE FROM student_list WHERE ID = '$id'";
$con->query($deleteSql) or die($con->error);
// Display a success alert
echo '<div class="alert alert-success mt-3" role="alert">
Student details deleted successfully!
</div>';
}
// Check if the ID parameter is provided in the URL
if (isset($_GET['id'])) {
$id = $_GET['id'];
// Retrieve the record from the database using the provided ID
$sql = "SELECT * FROM student_list WHERE ID = '$id'";
$result = $con->query($sql);
$row = $result->fetch_assoc();
} else {
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit - Student Management System</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css"> <!-- custom styles if needed -->
<link rel="icon" href="img/php-logo.svg" type="image/x-icon">
<style>
body {
background-color: #f4f4f4;
}
.header-link {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
background-color: #333;
color: #fff;
}
.header-link button {
background-color: #d9534f;
border-color: #d9534f;
}
.form-container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
.form-label {
font-weight: bold;
}
.form-control {
border: 1px solid #ccc;
border-radius: 5px;
padding: 8px;
}
.form-select {
border: 1px solid #ccc;
border-radius: 5px;
padding: 8px;
width: 100%;
}
.btn-primary,
.btn-danger {
padding: 0.25rem 0.5rem;
font-size: 0.8rem;
cursor: pointer;
}
.btn-success {
padding: 0.25rem 0.5rem;
font-size: 0.8rem;
cursor: pointer;
color: #fff;
background-color: #28a745;
border: none;
}
.btn-secondary {
padding: 0.25rem 0.5rem;
font-size: 0.8rem;
cursor: pointer;
background-color: #6c757d;
color: #fff;
border: none;
}
</style>
</head>
<body>
<div class="container mt-5">
<div class="header-link">
<div>
<h3 class="">Edit Student Details</h3>
</div>
</div>
<br>
<div class="form-container">
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="mb-3">
<label class="form-label">First Name</label>
<input type="text" name="firstname" class="form-control" value="<?php echo $row['first_name']; ?>">
</div>
<div class="mb-3">
<label class="form-label">Last Name</label>
<input type="text" name="lastname" class="form-control" value="<?php echo $row['last_name']; ?>">
</div>
<div class="mb-3">
<label class="form-label">Gender</label>
<select name="gender" class="form-select">
<option value="Male" <?php if ($row['gender'] === 'Male')
echo 'selected'; ?>>Male</option>
<option value="Female" <?php if ($row['gender'] === 'Female')
echo 'selected'; ?>>Female</option>
</select>
</div>
<button type="submit" name="update" class="btn btn-primary">Update</button>
</form>
<form action="" method="post" class="mt-3">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<button type="submit" name="delete" class="btn btn-danger">Delete</button>
</form>
<a href="index.php" class="btn btn-secondary mt-3">Back</a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>