-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_user.php
More file actions
208 lines (170 loc) · 4.9 KB
/
Copy pathedit_user.php
File metadata and controls
208 lines (170 loc) · 4.9 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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php
require_once "admin_middleware.php";
require_once "config.php";
/* -----------------------------
FETCH USER
------------------------------ */
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$user) {
die("User not found");
}
/* -----------------------------
UPDATE USER
------------------------------ */
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stmt = $pdo->prepare("
UPDATE users
SET full_name = ?, email = ?, role = ?, is_active = ?
WHERE id = ?
");
$stmt->execute([
$_POST['full_name'],
$_POST['email'],
$_POST['role'],
$_POST['status'],
$_POST['id']
]);
header("Location: users.php?updated=1");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit User</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
font-family: "Segoe UI", Tahoma, sans-serif;
background: #f4f6f9;
margin: 0;
padding: 30px;
}
.page-title {
font-size: 22px;
margin-bottom: 20px;
color: #333;
}
.card {
background: #fff;
max-width: 700px;
margin: auto;
padding: 25px;
border-radius: 10px;
box-shadow: 0 10px 30px rgba(0,0,0,0.08);
}
.form-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
.input-group {
display: flex;
flex-direction: column;
}
.input-group label {
font-size: 14px;
font-weight: 600;
margin-bottom: 6px;
color: #555;
}
.input-group input,
.input-group select {
padding: 12px;
border-radius: 6px;
border: 1px solid #ccc;
font-size: 15px;
}
.input-group input:focus,
.input-group select:focus {
outline: none;
border-color: #007bff;
}
.full-width {
grid-column: 1 / -1;
}
.actions {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 25px;
}
.btn {
padding: 12px 18px;
border-radius: 6px;
font-size: 14px;
border: none;
cursor: pointer;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 6px;
}
.btn-save {
background: #007bff;
color: #fff;
}
.btn-cancel {
background: #6c757d;
color: #fff;
}
.status-badge {
font-size: 12px;
padding: 4px 8px;
border-radius: 4px;
display: inline-block;
margin-left: 5px;
}
.active-badge { background: #28a745; color: #fff; }
.disabled-badge { background: #dc3545; color: #fff; }
@media (max-width: 600px) {
.form-grid {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<h2 class="page-title">✏️ Edit User Account</h2>
<div class="card">
<form method="post">
<input type="hidden" name="id" value="<?= $user['id'] ?>">
<div class="form-grid">
<div class="input-group">
<label>Full Name</label>
<input type="text" name="full_name"
value="<?= htmlspecialchars($user['full_name']) ?>" required>
</div>
<div class="input-group">
<label>Email Address</label>
<input type="email" name="email"
value="<?= htmlspecialchars($user['email']) ?>" required>
</div>
<div class="input-group">
<label>Role</label>
<select name="role">
<option value="admin" <?= $user['role']=='admin'?'selected':'' ?>>Admin</option>
<option value="teacher" <?= $user['role']=='teacher'?'selected':'' ?>>Teacher</option>
<option value="student" <?= $user['role']=='student'?'selected':'' ?>>Student</option>
</select>
</div>
<div class="input-group">
<label>Status</label>
<select name="status">
<option value="1" <?= $user['is_active'] ? 'selected' : '' ?>>Active</option>
<option value="0" <?= !$user['is_active'] ? 'selected' : '' ?>>Disabled</option>
</select>
</div>
</div>
<div class="actions">
<a href="users.php" class="btn btn-cancel">Cancel</a>
<button type="submit" class="btn btn-save">💾 Save Changes</button>
</div>
</form>
</div>
</body>
</html>