Here’s what I’m supposed to do:
Create a two-part form that calculates an employee’s weekly gross salary, based on the number of hours worked and an hourly wage that you choose. Use an HTML document as a Web form with two text boxes—one for the number of hours worked and one for the hourly wage. Use a PHP document 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.
Here’s my HTML file:
[code]
Calculate Your Pay
Number of Hours Worked:Hourly Wage:
[/code]
Here’s my PHP file:
[php]<?php
$hoursWorked = validateInput ($_POST[‘Hours’], “Hours”);
$wages = validateInput($_POST[‘Wage’], “Wage”);
if ($errorCount>0) {
echo “Please enter the information.
\n”;
redisplayForm($hoursWorked, $wages);
}
if (is_numeric($hoursWorked) && is_numeric($wages)){
if ($hoursWorked <= 40)
{
$payCheck = ($hoursWorked * $wages);
echo “
Your Wages Earned
You worked $hoursWorked hours at a rate of $$wages an hour.
Your pay total is: $$payCheck
”;
}
if ($hoursWorked > 40)
{
$payCheck = ($hoursWorked * $wages) + (($hoursWorked - 40) * $wages * 1.5);
echo “
Your Wages Earned
You worked $hoursWorked hours at a rate of $$wages an hour.
Your pay total is: $$payCheck
”;
}
}
else{
echo “
Only numbers can be used. Press the back button to try again.
”;//displayrequired($fieldName);
//(is_string($hoursWorked) && is_numeric($wages)==0)
//redisplayForm($hourWorked, $wages);
}
function displayRequired($fieldName) {
echo “The field “$fieldName” is required to calculate the wages earned.
\n”;
}
function validateInput($data, $fieldName) {
global $errorCount;
if (empty($data)) {
displayRequired($fieldName);
++$errorCount;
$retval = "";
}
else{
return ($data);
}
}
$errorCount=0;
function redisplayForm($hoursWorked, $wages) {
?>
Number of Hours Worked:
Hourly Wage:
<?php }
?>[/php]
The problem is when I try to validate incorrect data. Thanks in advance for any help