-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_user.php
More file actions
82 lines (68 loc) · 2.68 KB
/
edit_user.php
File metadata and controls
82 lines (68 loc) · 2.68 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
<?php
include('connect/connection.php');
include('UserController.php');
// Create a connection instance and retrieve the PDO connection
$database = new Connection();
$pdo = $database->getConnection();
// Instantiate the UserController
$userController = new UserController($pdo);
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$id = $_POST['id'];
$name = $_POST['name'];
$email = $_POST['email'];
$role = $_POST['Role']; // ✅ Capital "R" matches form
$status = $_POST['Status']; // ✅ Capital "S" matches form
// Update user details
$userController->updateUser($id, $name, $email, $role, $status);
// Redirect to the manage users page after updating
header("Location: manage_users.php");
exit();
}
// Fetch the user details by ID
$user = $userController->getUserById($_GET['id']);
?>
<!DOCTYPE html>
<html>
<head>
<title>Edit User</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h2>Edit User</h2>
<form method="POST">
<!-- Hidden field for user ID -->
<input type="hidden" name="id" value="<?php echo htmlspecialchars($user['id']); ?>">
<!-- Name Field -->
<div class="form-group">
<label>Name:</label>
<input type="text" name="name" value="<?php echo htmlspecialchars($user['name']); ?>" required class="form-control">
</div>
<!-- Email Field -->
<div class="form-group">
<label>Email:</label>
<input type="email" name="email" value="<?php echo htmlspecialchars($user['email']); ?>" required class="form-control">
</div>
<!-- Role Dropdown -->
<div class="form-group">
<label>Role:</label>
<select name="Role" class="form-control" required>
<option value="Admin" <?php echo ($user['Role'] == 'Admin') ? 'selected' : ''; ?>>Admin</option>
<option value="User" <?php echo ($user['Role'] == 'User') ? 'selected' : ''; ?>>User</option>
</select>
</div>
<!-- Status Dropdown -->
<div class="form-group">
<label>Status:</label>
<select name="Status" class="form-control" required>
<option value="Active" <?php echo ($user['Status'] == 'Active') ? 'selected' : ''; ?>>Active</option>
<option value="Inactive" <?php echo ($user['Status'] == 'Inactive') ? 'selected' : ''; ?>>Inactive</option>
</select>
</div>
<!-- Submit Button -->
<button type="submit" class="btn btn-primary">Update</button>
</form>
</div>
</body>
</html>