PHP Practical Slip 20 Q.B

Write a PHP script to accept employee details (name, address) and earning details
(basic, DA, HRA). Display employee details and earning details in the proper format.

<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $name = $_POST['name'];
    $address = $_POST['address'];
    $basic = $_POST['basic'];
    $da = $_POST['da'];
    $hra = $_POST['hra'];

    $total = $basic + $da + $hra;

    echo "<h2>Employee Details</h2>";
    echo "Name: " . $name . "<br>";
    echo "Address: " . $address . "<br><br>";

    echo "<h2>Earning Details</h2>";
    echo "Basic Salary: ₹" . $basic . "<br>";
    echo "DA: ₹" . $da . "<br>";
    echo "HRA: ₹" . $hra . "<br>";
    echo "<hr>";
    echo "<strong>Total Salary: ₹" . $total . "</strong>";
    echo "<br><br><a href=''>Back</a>";

    exit();
}
?>

<!DOCTYPE html>
<html>
<head>
    <title>Employee Information</title>
</head>
<body>

<h2>Employee Form</h2>

<form method="post" action="">
    
    <h3>Employee Details</h3>
    Name: <input type="text" name="name" required><br><br>
    Address: <input type="text" name="address" required><br><br>

    <h3>Earning Details</h3>
    Basic: <input type="number" name="basic" required><br><br>
    DA: <input type="number" name="da" required><br><br>
    HRA: <input type="number" name="hra" required><br><br>

    <input type="submit" value="Submit">

</form>

</body>
</html>
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top