BCA

WEB PROGRAMMING LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6

PART B

PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 PROGRAM 15 . . .

Question:

parameters: EmpId,EmployeeName,Designation,Department,Basic Salary,Allowance,Deduction
data file name : kumar.txt
{
"EmpId":1,
"Name":"kumar",
"Designation":"Assistant",
"Department":"ED",
"BasicSalary":45000,
"Allowance":15000,
"Deduction":9000
}

EMPLOYEE NAME 1:

EMPLOYEE NAME :-kumar
EmpId : 1
Name : kumar
Designation : Assistant
Department : ED
BasicSalary : 45000
Allowance : 15000
Deduction : 9000

Gross Salary =60000

NetSalary =51000

 
 
    Question:
<h6>parameters: EmpId,EmployeeName,Designation,Department,Basic Salary,Allowance,Deduction </h6>
<ul><li>
Write a PHP program to read the employee details from the text file and </li><li>
calculate the Gross and Net Salary of the employees.</li><li>
 Display the Gross and Net Salary of each employee along with the other details.</li><li>
(No need to update the text file after calculating the gross and net salary). </li><li>

The program, whenexecuted, should ask the file name containing the employee details. </li><li></ul>

<style>
table {
 
    width: 50%;
    border: 1px solid black;
}

th, td {
  text-align: left;
  padding: 8px;
 border: 1px solid black;
}
 
input[type="submit"] {
        
        padding: 12px 18px;
        cursor: pointer;
        border-radius: 5px;
        background-color: #8ebf42;
        font-size: 16px;
        font-weight: bold;
        color: #fff
      }
 
</style>

 <body>

data file name : kumar.txt
<br>
{<br>
"EmpId":1,<br>
"Name":"kumar",<br>
"Designation":"Assistant",<br>
"Department":"ED",<br>
"BasicSalary":45000,<br>
"Allowance":15000,<br>
"Deduction":9000<br>
}<br>
<hr>
        <form action="" method="post">
            EMPLOYEE NAME 1:
            <input type=text name="name" value="">
            <br>
                     <input type=submit name="submit">
            <br>
                    </form>
    </body>


< ?php

 $name="kumar";
if(isset($_POST['submit'])) // here isset function is using to check where a variable is set or not
{
    $name=$_POST['name'];// accessing value from first text field 
     
    echo "EMPLOYEE NAME  :-".$name;
}
    

$filename=$name.".txt";
$myfile = fopen($filename, "r") or die("Unable to open file!");

  
fclose($myfile);


  
$jsonstring = json_decode(file_get_contents ($filename));

 

   // var_dump( ($jsonstring));


    $basic= 0;
    $allowance=0;
     $deduction=0;

 echo"<table>";
foreach($jsonstring  as $key=>$value)
{

    echo "  <tr><td>$key :</td> ";

    echo "<td> $value  </td>";
       
        echo "<tr>";
        echo "\n";

       


}
echo"</table>";
        
    //Extracting data from json 
      $basic=  $jsonstring->BasicSalary;
     $allowance=$jsonstring->Allowance;
     $deduction=$jsonstring->Deduction;

  

        $GrossSalary = ($basic +$allowance) ;
        $NetSalary= $GrossSalary-$deduction;
    echo "<h2>Gross Salary  =".$GrossSalary."</h2>";
      echo "<h2>NetSalary =".$NetSalary."</h2>";


?>