Avatar of dvcrdu
dvcrdu
Flag for United States of America asked on

PHP Code

I have the following html form that has two text boxes "hours" and "wage". I need a PHP script that can compute the hours and any hours over 40 as time-and-a-half. Also the data must be validated to a decimal point value, even the hours. Can anyone help me?
<h2 style = "text-align:center">Enter Paycheck Data</h2>
<form name="paycheck" action="Paycheck.php" method="post">
<p>Hours Worked: <input type="text" name="hours" /></p>
<p>Hourly Wage: $<input type="text" name="wage" /></p>
<p><input type="reset" value="Clear Form" />&nbsp; 
     &nbsp;<input type="submit" name="Submit" 
     value="Send Form" /></p>
</form>

Open in new window

PHPHTMLWeb Applications

Avatar of undefined
Last Comment
dvcrdu

8/22/2022 - Mon
Michael701


$hours = $_POST['hours'];
$wage = $_POST['wage'];
$overtime=0;
if ($hours > 40) 
  $overtime = $hours-40;

$pay_amount = ($hours * $wage) + ($overtime * $wage * 1.5);

echo "Pay amount:".$pay_amount;

Open in new window

dvcrdu

ASKER
Will this also validate the data from the text boxes as well?

Thank you!
Michael701

not very much,

depends on how much checking you want

you could use something like this

if (!is_numeric($hours))
  echo "Hours is not a number.";
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
dvcrdu

ASKER
How can I put that in with your previous code?

Thank you!
ASKER CERTIFIED SOLUTION
Michael701

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dvcrdu

ASKER
Thank you!! That was awesome work!!!