Hi,
I am very very very new to PHP. I have a program that is meant for a user to put in hours worked and wages and the program will calculate the total and display. Only problem is it won’t work but I’m not getting any errors (using NetBeans). I realize my code is probably messy and I might be doing too much, but I’m using the “PHP Programming with MySQL” 2nd edition to guide me and it is no help. I would appreciate any help. I’m not asking you to do my homework, I’m just stuck. Thank you.
[php]
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 {
$retval= trim($data);
$retval = stripslashes($retval);
}
}
$errorCount = 0;
$hoursworked = "";
$wage = "";
$DisplayForm = TRUE;
if ($errorCount>0){
echo "Please use the back button to re-enter the data. <br />\n";
}
$regularpay= ($hoursworked * $wage);
$extrapay = ($hoursworked * $wage) + (($hoursworked -40) * $wage * .5);
if (isset($_POST["Submit"])) {
$hoursworked = $_POST["Hours"];
$wage = $_POST["Wages"];
if (is_numeric($hoursworked) && is_numeric($wage)) {
$DisplayForm = FALSE;
} else {
$DisplayForm= TRUE;
}
}
if ($DisplayForm) {
?>
<form name="PaycheckForm" action="PaycheckFrailey.php"
method="post">
<p>Enter your hours worked: <input type="text" name="Hours"
value ="<?php echo $hoursworked; ?>" /><br />
Hourly Wage: <input type="text" name="Wages"
value ="<?php echo $wage; ?>" /><br /></p>
<p><input type ="submit" name="Submit" value="Send Form" />
</form>
<?php
}
if (isset($_POST ["Submit"])) {
$hoursworked= filter_input(\INPUT_POST, "Hours");
$wage = filter_input(\INPUT_POST, "Wage");
$errorCount ="";
if (is_numeric($hoursworked) && is_numeric ($wage)) {
if ($hoursworked <=40) { // Calculate regular pay
$regularpay = ($hoursworked * $wage);
} else { // Calculate time and half
$extrapay = ($hoursworked * $wage) + ((hoursworked -40) * $wage * .5);
}
}
$totalpay = $regularpay + $extrapay;
echo "<p>Your paycheck is worth \$$totalpay. </p>"; }[/php]