Solved

PHP Code

Posted on 2010-09-07
6
621 Views
Last Modified: 2012-06-21
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

0
Comment
Question by:dvcrdu
  • 3
  • 3
6 Comments
 
LVL 19

Expert Comment

by:Michael701
Comment Utility

$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

0
 

Author Comment

by:dvcrdu
Comment Utility
Will this also validate the data from the text boxes as well?

Thank you!
0
 
LVL 19

Expert Comment

by:Michael701
Comment Utility
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.";
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:dvcrdu
Comment Utility
How can I put that in with your previous code?

Thank you!
0
 
LVL 19

Accepted Solution

by:
Michael701 earned 500 total points
Comment Utility

$hours = $_POST['hours'];

$wage = $_POST['wage'];

$overtime=0;

if ($hours > 40) 

  $overtime = $hours-40;



if (!is_numeric($hours))

  echo "Hours is not a number.";



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



echo "Pay amount:".$pay_amount;

Open in new window

0
 

Author Closing Comment

by:dvcrdu
Comment Utility
Thank you!! That was awesome work!!!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now