Question
This is a PHP/HTML Script Assignment question from book: PHP Programming with MySQL V2 I am having hard time with stylistic conventions and comments. Please
This is a PHP/HTML Script Assignment question from book: PHP Programming with MySQL V2
I am having hard time with stylistic conventions and comments. Please add comments, author name, function etc in your code.
Bottom of the question is the code I have but I am having trouble with using the $_POST super global in paycheck.php as you work with the received form fields. You can improve my code or write new one.
Question:
Create a two-part form that calculates an employees weekly gross salary, based on the number of hours worked and an hourly wage that you choose. Use an HTML document named Paycheck.html as a Web form with two text boxesone for the number of hours worked and one for the hourly wage. Use a PHP document named Paycheck.php as the form handler. Compute any hours over 40 as time-and-a-half. Be sure to verify and validate the submitted form data and provide appropriate error messages for invalid values.
Html code :
Paycheck Calculator
-----------------------------------------------------------------------------------------------------
Php code
$hours = $_GET["hours"];
$wages = $_GET["wage"];
if (is_numeric ($hours) and is_numeric($wages))
{
if ($hours > 60 ) {
echo "Worked more than 60 hours";
}
else if ($hours>0 and $wages>0)
{
$overtime = max($hours - 40, 0);
$pay += $overtime * $wages * 1.5;
$pay += ($hours - $overtime) * $wages;
echo "Hours Worked: " . $hours . " ";
echo "Pay rate (per hour): $" . number_format($wages, 2) . " ";
echo "Overtime Hours: " . $overtime . " ";
echo "Your Paycheck is: $" . number_format($pay, 2) . " ";
}
else
{
echo "incorrect input: wages or hours worked should be greater than zero(0)";
}
}
else
{
echo "hours worked or wage rate should be numeric ";
}
?>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started