182. PHP Program to store Employe records in tabular formate.
How does this program work?
- In this program you are going to learn about how to store Employe records in tabular formate using PHP.
- By using given code we can store the employe records in tabular formate.
Here is the code
<?php
if(isset($_POST[ 'submit'])) {
$arr = array();
$arr = $_POST[ 'Fid'];
echo "<table>\n";
echo "<tr><th> ID </th><th> Name </th>
<th> Age </th><th> Salary </th>
<th> DA </th><th> PF </th>
<th> TAX </th><th> HRA </th>
<th> TA </th></tr>\n";
foreach($arr as $key=>$value)
{
echo "<tr>";
echo "<td>" . $value . "</td>\n";
echo "<td>" . $_POST['Fage'][$key] . "</td>\n";
echo "<td>" . $_POST['Fage'][$key] . "</td>\n";
echo "<td>" . $_POST['Fsalary'][$key] . "</td>\n";
echo "<td>" . $_POST['Fda'][$key] . "</td>\n";
echo "<td>" . $_POST['Fpf'][$key] . "</td>\n";
echo "<td>" . $_POST['Ftax'][$key] . "</td>\n";
echo "<td>" . $_POST['Fhra'][$key] . "</td>\n";
echo "<td>" . $_POST['Fta'][$key] . "</td>\n";
echo "</tr>";
}
echo "</table>";
return 0;
}
?>
<html>
<head>
<title>PHP Program To store Employe records in tabular formate</title>
</head>
<body>
<form method="post">
<table border="0">
<tr>
<td> <input type="text" id="num1" name="num1" value="" placeholder="Enter array size"/> </td>
</tr>
<div id="screens">
</div>
<tr>
<td> <input type="submit" name="submit" value="Submit"/> </td>
</tr>
</table>
</form>
</body>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
function create(param)
{
'use strict';
var i;
$("#screens").empty();
for (i = 0; i < param; i += 1)
{
$('#screens').append('<input type="text" name="Fid[]" placeholder="Enter id">');
$('#screens').append('<input type="text" name="Fname[]" placeholder="Enter name">');
$('#screens').append('<input type="text" name="Fage[]" placeholder="Enter age">');
$('#screens').append('<input type="text" name="Fsalary[]" placeholder="Enter salary">');
$('#screens').append('<input type="text" name="Fda[]" placeholder="Enter DA">');
$('#screens').append('<input type="text" name="Fpf[]" placeholder="Enter PF">');
$('#screens').append('<input type="text" name="Ftax[]" placeholder="Enter TAX">');
$('#screens').append('<input type="text" name="Fhra[]" placeholder="Enter HRA">');
$('#screens').append('<input type="text" name="Fta[]" placeholder="Enter TA">');
}
}
$('#num1').change(function ()
{
create($(this).val());
});
</script>
</html>