PHP help, I seem to be getting stuck with getting this program to come to life.
ID: 3885497 • Letter: P
Question
PHP help, I seem to be getting stuck with getting this program to come to life.
Create a form to allow the user to enter employee’s name, pay rate, and weekly hours work. That information will be sent to a PHP script that will process and display the employee’s paycheck information. Your assignment should have two pages. The first page is straight HTML (users_input.html) that has a form with the appropriate form elements to collect the user input. The form should then be submitted using the POST method to a PHP script (show_paycheck.php) that will process the user input.
users_input.html
The PHP script (show_paycheck.php) will receive the user input, assign it to variables, calculate and display the following pay check information:
Gross Pay (hours worked times pay rate)
Federal Taxes (10.65% of Gross Pay)
State Taxes (4% of Gross Pay)
Social Security Taxes (3.8% of Gross Pay)
Medicare (1.3% of Gross Pay)
Total Taxes (Federal + State + Social Security + Medicare)
Net Pay (Gross Pay – Total Taxes
For all the above calculations, will be assigned to variables that have descriptive names. The PHP script should calculate and display the results in the following format. The left column of the table must be bold and left justified, and the right column is right justified. There is also a link to return back to the users_input.html page.
show_paycheck.php example
lease enter employee info First Name: Last Name: Weekly Hours Worked: Hourly Rate S: Submit ResetExplanation / Answer
users_input.html will contain the following code:
<!DOCTYPE html>
<html>
<body>
<style>
form { display: table; }
p { display: table-row; }
label { display: table-cell; }
input { display: table-cell; }
</style>
<form action="show_paycheck.php" method="post">
<p>
<label for="a">First Name:</label>
<input id="a" type="text">
</p>
<p>
<label for=“b”>Last Name:</label>
<input id=“b” type="text">
</p>
<p>
<label for=“c”>Weekly Hours Worked:</label>
<input id=“c” type="number">
</p>
<p>
<label for=“d”>Hourly Rate $:</label>
<input id=“d” type="number">
</p>
<input type="submit" value="Submit">
<label><input type="reset" value="Reset"></label>
</form>
</body>
</html>
show_paycheck.php will contain the following code:
<html>
<body>
<style>
table, th, td {
border: 1px solid black;
}
</style>
<h1> Paycheck Information </h1>
<?php
$firstName = $_POST["First Name:"];
$lastName = $_POST["Last Name:"];
$weeklyHoursWorked = $_POST["Weekly Hours Worked:"];
$hourlyRate = $_POST["Hourly Rate $:"];
$grossPay = weeklyHoursWorked*hourlyRate;
$federalTaxes = 0.1065*grossPay;
$stateTaxes = 0.04*grossPay;
$socialSecurityTaxes = 0.038*grossPay;
$medicare = 0.013*grossPay;
$totalTaxes = medicare+ socialSecurityTaxes+ stateTaxes + federalTaxes;
$netPay = grossPay - totalTaxes;
echo "Welcome $firstName $lastName. This week you worked for $weeklyHoursWorked hours and, based on the pay rate of $$hourlyRate per hour, your paycheck information is: ";
?>
</p>
<br>
<br>
<table>
<tr>
<td>Gross Pay</td>
<td align="right"><?php echo "$$hourlyRate"; ?><td>
</tr>
<tr>
<td>Federal Taxes</td>
<td align="right"><?php echo "$$federalTaxes"; ?><td>
</tr>
<tr>
<td>State Taxes</td>
<td align="right"><?php echo "$$stateTaxes"; ?><td>
</tr>
<tr>
<td>Social Security Taxes</td>
<td align="right"><?php echo "$$socialSecurityTaxes"; ?><td>
</tr>
<tr>
<td>Total Taxes</td>
<td align="right"><?php echo "$$totalTaxes"; ?><td>
</tr>
<tr>
<td>Net Pay</td>
<td align="right"><?php echo "$$netPay"; ?><td>
</tr>
</table>
<a href="users_input.html">Return to input form</a>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.