-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaff_edit.php
More file actions
88 lines (80 loc) · 3.85 KB
/
staff_edit.php
File metadata and controls
88 lines (80 loc) · 3.85 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
<?php
// staff_edit.php
include 'header.php';
include 'sidebar.php';
$staff_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$update_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['staff_id'])) {
$staff_id = intval($_POST['staff_id']);
$client_name = trim($_POST['client_name']);
$name = trim($_POST['name']);
$user_id = trim($_POST['user_id']);
$status = trim($_POST['status']);
$sql = "UPDATE staff SET client_name=?, name=?, user_id=?, status=? WHERE id=?";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("ssssi", $client_name, $name, $user_id, $status, $staff_id);
if ($stmt->execute()) {
$update_message = "<div class='bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded'>Staff details updated successfully!</div>";
} else {
$update_message = "<div class='bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded'>Error: " . $stmt->error . "</div>";
}
$stmt->close();
}
}
$staff = null;
if ($staff_id > 0) {
$stmt = $conn->prepare("SELECT * FROM staff WHERE id = ?");
$stmt->bind_param("i", $staff_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 1) {
$staff = $result->fetch_assoc();
}
$stmt->close();
}
$conn->close();
?>
<!-- Main Content -->
<div class="bg-white p-8 rounded-lg shadow-md w-full">
<h4 class="text-2xl font-bold text-gray-700 mb-6">Edit Staff</h4>
<?php echo $update_message; ?>
<?php if ($staff): ?>
<form action="staff_edit.php?id=<?php echo $staff_id; ?>" method="post">
<input type="hidden" name="staff_id" value="<?php echo $staff['id']; ?>">
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Client Name</label>
<input type="text" name="client_name" value="<?php echo htmlspecialchars($staff['client_name']); ?>"
class="shadow border rounded w-full py-2 px-3 text-gray-700">
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Name</label>
<input type="text" name="name" required value="<?php echo htmlspecialchars($staff['name']); ?>"
class="shadow border rounded w-full py-2 px-3 text-gray-700">
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">User ID</label>
<input type="text" name="user_id" required value="<?php echo htmlspecialchars($staff['user_id']); ?>"
class="shadow border rounded w-full py-2 px-3 text-gray-700">
</div>
<div>
<label class="block text-gray-700 text-sm font-bold mb-2">Status</label>
<select name="status" class="shadow border rounded w-full py-2 px-3 text-gray-700">
<option value="Enable" <?php echo ($staff['status'] == 'Enable') ? 'selected' : ''; ?>>Enable</option>
<option value="Disable" <?php echo ($staff['status'] == 'Disable') ? 'selected' : ''; ?>>Disable
</option>
</select>
</div>
</div>
<div class="mt-8 flex justify-end">
<a href="staff_master.php"
class="bg-gray-500 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded mr-2">Back to List</a>
<button type="submit" class="bg-pink-600 hover:bg-pink-700 text-white font-bold py-2 px-4 rounded">Save
Changes</button>
</div>
</form>
<?php else: ?>
<p class="text-red-500">Staff member not found.</p>
<?php endif; ?>
</div>
<?php include 'footer.php'; ?>