Solved

PHP Code

Posted on 2010-09-07
6
628 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
ID: 33623209

$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
ID: 33623368
Will this also validate the data from the text boxes as well?

Thank you!
0
 
LVL 19

Expert Comment

by:Michael701
ID: 33623409
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:dvcrdu
ID: 33623437
How can I put that in with your previous code?

Thank you!
0
 
LVL 19

Accepted Solution

by:
Michael701 earned 500 total points
ID: 33623569

$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
ID: 33623778
Thank you!! That was awesome work!!!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

813 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

16 Experts available now in Live!

Get 1:1 Help Now