-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_edit_employee.php
More file actions
40 lines (35 loc) · 1.4 KB
/
process_edit_employee.php
File metadata and controls
40 lines (35 loc) · 1.4 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
<?php
// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the updated employee data from the form
$employeeName = $_POST['employeeName'];
$employeeContact = $_POST['employeeContact'];
$employeeAddress = $_POST['employeeAddress'];
$employeeSalary = $_POST['employeeSalary'];
$employeeCompany = $_POST['employeeCompany'];
// Assuming you have already included the database connection code here...
// Prepare and execute the update statement
$stmt = mysqli_prepare($conn, "UPDATE employee SET emp_name = ?, emp_contact = ?, emp_address = ?, emp_salary = ?, company_id = ? WHERE emp_id = ?");
mysqli_stmt_bind_param($stmt, "ssssii", $employeeName, $employeeContact, $employeeAddress, $employeeSalary, $employeeCompany, $emp_id);
if (mysqli_stmt_execute($stmt)) {
// Update successful
$response = [
'success' => true,
'message' => 'Employee data updated successfully.'
];
} else {
// Update failed
$response = [
'success' => false,
'message' => 'Failed to update employee data.'
];
}
// Close the statement and connection
mysqli_stmt_close($stmt);
mysqli_close($conn);
// Return the response as JSON
header('Content-Type: application/json');
echo json_encode($response);
exit();
}
?>