Link to home
Get AccessLog in
Avatar of dvcrdu
dvcrduFlag 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

Avatar of Michael701
Michael701
Flag of United States of America image


$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

Avatar of dvcrdu

ASKER

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

Thank you!
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.";
Avatar of dvcrdu

ASKER

How can I put that in with your previous code?

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of Michael701
Michael701
Flag of United States of America image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of dvcrdu

ASKER

Thank you!! That was awesome work!!!