View Employee
View Employee
php
session_start();
// Database connection
$conn = new mysqli('localhost', 'root', '', 'payroll_system');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($result->num_rows > 0) {
$employee = $result->fetch_assoc();
} else {
echo "Employee not found!";
exit;
}
} else {
echo "Employee ID is missing!";
exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Get the form data
$first_name = trim($_POST['first_name']);
$middle_name = trim($_POST['middle_name']);
$last_name = trim($_POST['last_name']);
$position = trim($_POST['position']);
$project_name = trim($_POST['project_name']);
$project_location = trim($_POST['project_location']);
$phone = trim($_POST['phone']);
$email = trim($_POST['email']);
$address = trim($_POST['address']);
$dob = trim($_POST['dob']);
$supervisor = trim($_POST['supervisor']);
$department = trim($_POST['department']);
$salary = trim($_POST['salary']);
$overtime_rate = trim($_POST['overtime_rate']);
$gender = trim($_POST['gender']);
$bank_account = trim($_POST['bank_account']);
$emergency_contact_name = trim($_POST['emergency_contact_name']);
$relationship = trim($_POST['relationship']);
$emergency_contact_phone = trim($_POST['emergency_contact_phone']);
$salary_frequency= trim($_POST['salary_frequency']);
$employment_status= trim($_POST['employment_status']);
$date_of_hire= trim($_POST['date_of_hire']);
if ($update_stmt->execute()) {
$_SESSION['message'] = "Employee updated successfully!";
header('Location: employee_list.php'); // Redirect back to the employee
list
exit;
} else {
$_SESSION['message'] = "Error updating employee: " . $conn->error;
}
}
$conn->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>View Employee</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background-color: #f0f2f5;
display: flex;
min-height: 100vh;
overflow-x: hidden;
}
.sidebar {
width: 250px;
background: linear-gradient(135deg, #007bff, #0056b3);
color: #fff;
height: 100vh;
position: fixed;
padding: 20px;
}
.sidebar h2 {
font-size: 24px;
margin-bottom: 20px;
text-align: center;
}
.sidebar ul {
list-style: none;
padding: 0;
}
.sidebar ul li {
margin: 15px 0;
}
.sidebar ul li a {
color: #fff;
text-decoration: none;
font-size: 18px;
display: block;
padding: 10px;
border-radius: 5px;
}
.sidebar ul li a:hover {
background-color: #0056b3;
}
.main-content {
margin-left: 250px;
padding: 20px;
width: 100%;
}
.form-container {
background-color: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.form-container h3 {
margin-bottom: 20px;
text-align: center;
}
.form-container .section-title {
font-size: 18px;
margin-top: 20px;
margin-bottom: 10px;
font-weight: bold;
}
.form-container label {
font-size: 16px;
margin-bottom: 8px;
display: block;
}
.form-container .row {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.form-container .column {
flex: 1;
min-width: calc(33.33% - 20px);
}
.form-container input,
.form-container select,
.form-container textarea {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border-radius: 5px;
border: 1px solid #ccc;
font-size: 16px;
}
#employee_id {
width: calc(100% - 66%);
}
.form-container button {
width: auto;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
margin-top: 20px;
}
.form-container button:hover {
background-color: #0056b3;
}
</style>
</head>
<script>
document.addEventListener('DOMContentLoaded', function() {
const projectSelect = document.getElementById('projects');
const projectLocationInput = document.getElementById('project_location');
// Update the project location input field with the selected project
location
projectLocationInput.value = projectLocation;
});
});
</script>
<body>
<!-- Sidebar -->
<div class="sidebar">
<h2>Payroll System</h2>
<ul>
<li><a href="dashboard.php">Dashboard</a></li>
<li><a href="employee_list.php">Employee List</a></li>
<li><a href="#">Payroll List</a></li>
<li><a href="department_list.php">Department Lists</a></li>
<li><a href="position_list.php">Position Lists</a></li>
<li><a href="allowance_list.php">Allowance Lists</a></li>
<li><a href="deduction_list.php">Deduction Lists</a></li>
<li><a href="projects.php">Project Lists</a></li>
<li><a href="attendance_list.php">Attendance</a></li>
<li><a href="list_users.php">Admin Account Lists</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="column">
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" value="<?
php echo htmlspecialchars($employee['last_name']); ?>" required>
<label for="gender">Gender:</label>
</div>
<div class="column">
<label for="middle_name">Middle Name/Initial:</label>
<input type="text" name="middle_name" value="<?php echo
htmlspecialchars($employee['middle_name']); ?>" required>
<label for="email">Email:</label>
<input type="text" name="email" value="<?php echo
htmlspecialchars($employee['email']); ?>">
<label for="address">Address:</label>
<input type="text" name="address" value="<?php echo
htmlspecialchars($employee['address']); ?>" required>
</div>
</div>
<label for="department">Department:</label>
<input type="text" name="department" value="<?php echo
htmlspecialchars($employee['department']); ?>" required>
</div>
<div class="column">
<label for="project_name">Project Name:</label>
<input type="text" name="projects" value="<?php echo
htmlspecialchars($employee['project_name']); ?>" required>
<select id="employment_status"
name="employment_status" required>
<option value="Full-time" <?php echo
($employee['employment_status'] === 'Full-time') ? 'selected' : '';
?>>Full-time</option>
<option value="Part-time" <?php echo
($employee['employment_status'] === 'Part-time') ? 'selected' : '';
?>>Part-time</option>
<option value="Contract" <?php echo
($employee['employment_status'] === 'Contract') ? 'selected' : '';
?>>Contract</option>
</select>
<label for="supervisor">Supervisor/Manager:</label>
<input type="text" name="supervisor" value="<?php echo
htmlspecialchars($employee['supervisor']); ?>" required>
</div>
</div>
</select>