Solved

PHP Code

Posted on 2010-09-07
6
641 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

617 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