0% found this document useful (0 votes)
3 views3 pages

Web Technology

The document consists of an HTML form for capturing employee details and a PHP script for processing the submitted data. It calculates the gross salary based on working hours and hourly rate, stores employee information in PHP sessions, and displays the details in a table along with the total salary expense. The form and script work together to manage employee pay slip information effectively.

Uploaded by

Sharan Sha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Web Technology

The document consists of an HTML form for capturing employee details and a PHP script for processing the submitted data. It calculates the gross salary based on working hours and hourly rate, stores employee information in PHP sessions, and displays the details in a table along with the total salary expense. The form and script work together to manage employee pay slip information effectively.

Uploaded by

Sharan Sha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1. HTML Form (pay_slip_form.

html): Captures employee details and submits them to


<!DOCTYPE html>
<html>
<head>
<title>Employee Pay Slip</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid black; padding: 10px; text-align: center; }
th { background-color: #f2f2f2; }
.container { max-width: 500px; margin: auto; }
</style>
</head>
<body>
<div class="container">
<h2>Employee Pay Slip Form</h2>
<form action="pay_slip.php" method="post">
<label>Name:</label>
<input type="text" name="name" required><br><br>
<label>Working Hours:</label>
<input type="number" name="hours" required><br><br>
<label>Hourly Rate:</label>
<input type="number" name="rate" required><br><br>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
2. PHP Script (pay_slip.php):
<?php
session_start();
if (!isset($_SESSION['employees'])) {
$_SESSION['employees'] = [];
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$hours = (int)$_POST['hours'];
$rate = (float)$_POST['rate'];

// Calculate gross salary


if ($hours <= 50) {
$gross_salary = $hours * $rate;
} else {
$gross_salary = (50 * $rate) + (($hours - 50) * $rate * 2);
}

// Store employee details


$_SESSION['employees'][] = [
'name' => $name,
'hours' => $hours,
'rate' => $rate,
'gross_salary' => $gross_salary
];
}

// Calculate total salary expense


$total_salary = array_sum(array_column($_SESSION['employees'], 'gross_salary'));
?>

<!DOCTYPE html>
<html>
<head>
<title>Pay Slip Details</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid black; padding: 10px; text-align: center; }
th { background-color: #f2f2f2; }
</style>
</head>
<body>
<h2>Employee Salary Details</h2>
<table>
<tr>
<th>Name</th>
<th>Working Hours</th>
<th>Hourly Rate</th>
<th>Gross Salary</th>
</tr>
<?php foreach ($_SESSION['employees'] as $employee): ?>
<tr>
<td><?php echo htmlspecialchars($employee['name']); ?></td>
<td><?php echo $employee['hours']; ?></td>
<td><?php echo $employee['rate']; ?></td>
<td><?php echo number_format($employee['gross_salary'], 2); ?></td>
</tr>
<?php endforeach; ?>
</table>
<h3>Total Salary Paid: <?php echo number_format($total_salary, 2); ?></h3>
</body>
</html>

- Processes submitted data.

- Calculates the gross salary based on the given conditions.

- Stores the data using PHP sessions to keep a cumulative record of employees.

- Displays all employee details in a table.

- Computes and displays the total salary expense.

You might also like