0% found this document useful (0 votes)
17 views9 pages

View Employee

This PHP script manages employee data in a payroll system, ensuring that only logged-in users can access it. It retrieves employee information from a database based on an employee ID passed in the URL, allows for editing of various employee details, and updates the database upon form submission. The script also includes HTML and CSS for the user interface, which features a sidebar for navigation and a form for viewing and editing employee information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

View Employee

This PHP script manages employee data in a payroll system, ensuring that only logged-in users can access it. It retrieves employee information from a database based on an employee ID passed in the URL, allows for editing of various employee details, and updates the database upon form submission. The script also includes HTML and CSS for the user interface, which features a sidebar for navigation and a form for viewing and editing employee information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

<?

php
session_start();

// Check if the user is logged in


if (!isset($_SESSION['username'])) {
header('Location: login.php');
exit;
}

// Database connection
$conn = new mysqli('localhost', 'root', '', 'payroll_system');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Check if the employee_id is passed in the URL


if (isset($_GET['employee_id'])) {
$employee_id = $_GET['employee_id'];

// Fetch the employee data from the database


$sql = "SELECT * FROM employees WHERE employee_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $employee_id);
$stmt->execute();
$result = $stmt->get_result();

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']);

// Update the employee data in the database


$update_sql = "UPDATE employees
SET first_name = ?,
middle_name = ?,
last_name = ?,
position = ?,
project_name = ?,
project_location = ?,
phone = ?,
email = ?,
address = ?,
dob = ?,
supervisor = ?,
department = ?,
salary = ?,
overtime_rate = ?,
gender = ?,
bank_account = ?,
emergency_contact_name = ?,
relationship = ?,
emergency_contact_phone = ?,
salary_frequency = ?,
employment_status = ?,
date_of_hire = ?
WHERE employee_id = ?";
$update_stmt = $conn->prepare($update_sql);
$update_stmt->bind_param(
"sssssssssssssssssssissi",
$first_name,
$middle_name,
$last_name,
$position,
$project_name,
$project_location,
$phone,
$email,
$address,
$dob,
$supervisor,
$department,
$salary,
$overtime_rate,
$gender,
$bank_account,
$emergency_contact_name,
$relationship,
$emergency_contact_phone,
$salary_frequency,
$employment_status,
$date_of_hire,
$employee_id
);

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');

// Event listener for when the project selection changes


projectSelect.addEventListener('change', function() {
const selectedOption =
projectSelect.options[projectSelect.selectedIndex];
const projectLocation = selectedOption.getAttribute('data-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>

<!-- Main Content -->


<div class="main-content">
<div class="form-container">
<h3>View/Edit Employee</h3>

<?php if (isset($_SESSION['message'])): ?>


<div class="message"><?php echo $_SESSION['message']; ?></div>
<?php unset($_SESSION['message']); ?>
<?php endif; ?>

<form action="view_employee.php?employee_id=<?php echo


$employee['employee_id']; ?>" method="post">

<!-- Employee ID Section -->


<div class="section-title">Employee ID</div>
<div class="row">
<div class="column">

<input type="text" id="employee_id"


name="employee_id" value="<?php echo htmlspecialchars($employee['employee_id']); ?
>" readonly>

</div>
</div>

<!-- Personal Information -->


<div class="section-title">Personal Information</div>
<div class="row">
<div class="column">
<label for="first_name">First Name:</label>
<input type="text" name="first_name" value="<?
php echo htmlspecialchars($employee['first_name']); ?>" required>

<label for="phone">Phone Number:</label>


<input type="text" name="phone" value="<?
php echo htmlspecialchars($employee['phone']); ?>" required>

</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="dob">Date of Birth:</label>

<input type="date" name="dob" value="<?php


echo htmlspecialchars($employee['dob']); ?>" required>

<label for="gender">Gender:</label>

<select id="gender" name="gender" required>


<option value="Male" <?php echo
($employee['gender'] === 'Male') ? 'selected' : ''; ?>>Male</option>
<option value="Female" <?php echo
($employee['gender'] === 'Female') ? 'selected' : ''; ?>>Female</option>
<option value="Other" <?php echo
($employee['gender'] === 'Other') ? 'selected' : ''; ?>>Other</option>
</select>

</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>

<!-- Employment Information -->


<div class="section-title">Employment Information</div>
<div class="row">
<div class="column">
<label for="date_of_hire">Date of Hiring:</label>

<input type="date" name="date_of_hire"


value="<?php echo htmlspecialchars($employee['date_of_hire']); ?>" required>
<label for="position">Position/Designation:</label>
<input type="text" name="position" value="<?php echo
htmlspecialchars($employee['position']); ?>" required>

<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>

<label for="project_location">Project Location:</label>


<input type="text" name="project_location" value="<?php
echo htmlspecialchars($employee['project_location']); ?>" required>
</div>
<div class="column">
<label for="employment_status">Employment Status:</label>

<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>

<!-- Salary and Compensation -->


<div class="section-title">Salary and Compensation</div>
<div class="row">
<div class="column">
<label for="salary">Base Salary/Hourly Rate:</label>
<input type="number" name="salary" value="<?php echo
htmlspecialchars($employee['salary']); ?>" required>

<label for="overtime_rate">Overtime Rate:</label>


<input type="number" name="overtime_rate" value="<?
php echo htmlspecialchars($employee['overtime_rate']); ?>" required>
</div>
<div class="column">
<label for="bonus_eligibility">Bonus Eligibility:</label>
<input type="checkbox" name="bonus_eligibility"
value="Yes"> Eligible for Bonus
</div>
<div class="column">
<label for="salary_frequency">Salary Frequency:</label>

<select id="salary_frequency" name="salary_frequency"


required>
<option value="weekly" <?php echo
($employee['salary_frequency'] === 'Weekly') ? 'selected' : ''; ?>>Weekly</option>
<option value="Bi-weekly" <?php echo
($employee['salary_frequency'] === 'Bi-weekly') ? 'selected' : '';
?>>Bi-weekly</option>
<option value="Monthly" <?php echo
($employee['salary_frequency'] === 'Monthly') ? 'selected' : '';
?>>Monthly</option>

</select>

<label for="bank_account">Bank Account Details:</label>


<input type="text" name="bank_account" value="<?php echo
htmlspecialchars($employee['bank_account']); ?>">
</div>
</div>

<!-- Emergency Information -->


<div class="section-title">Emergency Information</div>
<div class="row">
<div class="column">
<label for="emergency_contact_name">Emergency Contact
Name:</label>
<input type="emergency_contact_name"
name="emergency_contact_name" value="<?php echo
htmlspecialchars($employee['emergency_contact_name']); ?>" required>
</div>
<div class="column">
<label for="relationship">Relationship:</label>
<input type="text" name="relationship" value="<?php echo
htmlspecialchars($employee['relationship']); ?>" required>
</div>
<div class="column">
<label for="emergency_contact_phone">Emergency Contact
Phone:</label>
<input type="text" name="emergency_contact_phone" value="<?
php echo htmlspecialchars($employee['emergency_contact_phone']); ?>" required>
</div>
</div>

<!-- Submit Button -->


<button type="submit">Save Changes</button>
</form>
</div>
</div>
</body>
</html>

You might also like