PHP Program to Create Class Employee to Accept and Display Data
Question: Write a PHP program to create a class employee with data members eno, name, salary, designation and memeber functions to accept data and display data. Accept data for 5 employees and display the information.
HTML Code to Accept Employee Information
<html>
<head><title>Fill Employee Details</title>
<body>
<h2>Enter Information for 5 Employees (Use space for separation)</h2>
<form action="employee.php" method="">
Enter Employee Nos:
<input name="nos" type="text" /><br />
Enter Employee names:
<input name="names" type="text" /><br />
Enter respective salaries:
<input name="sal" type="text" /><br />
Enter designations:
<input name="des" type="text" /><br /><br />
<input type="submit" /><input type="reset" /><br />
</form>
</body>
</head></html>
PHP Code to Display the Accepted Employee Information
eno = $eno;
$this->name = $name;
$this->sal = $sal;
$this->des = $des;
}
public function display data()
{
echo "Employee no is $eno
";
echo "Employee name is $name
";
echo "Employee salary is $sal
";
echo "Employee designation is $des
";
}
}
$emp_info_array[] = new Employee();
for($i = 0; $i < 5; $i++)
{
$emp_info_array[$i] = new Employee();
$emp_info_arrays[$i]->acceptData($enos[$i], $names[$i], $salaries[$i],$des[$i]);
$emp_info_array[$i].displayData();
}
?>