| | |
My script needs help-Calculate a Paycheck
![]() |
•
•
Join Date: Feb 2007
Posts: 20
Reputation:
Solved Threads: 0
HI Can someone please help me. the book sucks, teacher will not help me (says I will not learn), I am trying to calculate Pay check. Just hours worked, pay, and overtime.
:rolleyes:
Script is as follows:
Thanks
:rolleyes:
Script is as follows:
php Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Calculate Your PayCheck</title> </head> <body> <h1>Calculate Your Paycheck</h1> <form method = "post" action = "Paycheck.php"> <table border = 1> <tr> <th>Hours Worked <input type = "integer" name = "hoursWorked" value = ""> </th> </tr> <tr> <th>Wages <input type = "integer" name = "wages" value = ""> </th> </tr> <tr> <td colspan = 2> <center> <input type = "Submit" value = "Submit"> </center> </td> </tr> </table> <?PHP $hoursWorked = $_REQUEST["hoursWorked"] $wages = $_REQUEST["wages"] $pay = $_REQUEST["pay"] $payCheck = $_REQUEST["payCheck"] $x = hoursWorked; $y = wages; $z = pay; $zz = overtimeHours; if ($x is <= 40){ $submit = ("$x * $y = $z") echo "Your Paycheck is: $paycheck"; } if ($x is > 40){ $submit = ("$x - 40 * $y * 1.5 =$z") echo "Your Paycheck is: $paycheck"; } ?> </center> </form> </body> </html>
Thanks
Last edited by stymiee; Feb 25th, 2007 at 11:59 am. Reason: added code tags
Where are you having problems?
John Conde
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
Brainyminds | Merchant Account Services | I Love Code
IT'S HERE: Merchant Accounts 101 Everything you need to know about merchant accounts!
•
•
Join Date: Feb 2007
Posts: 20
Reputation:
Solved Threads: 0
When it shows in the browser, part of the code (with the if expressions ..I think) shows on the site. Also when I hit Submit, I do not get results. I know it is probably really simple, but I am very frustrated because I cannot find answers or a pattern to go by. Thanks for replying and I will be so grateful. I am behind on all my projects for PHP class.
Look at the lines where you have $x =, $y =, etc. Firstly, you are trying to set one variable equal to another, but you aren't putting dollar signs in front of all your variables. It should be
I haven't had a chance to look over any of your logic yet. This is just syntax errors.
$x = $hoursWorked and not $x = hoursWorked. Also, you're setting $zz equal to $overtimeHours but that variable isn't set.I haven't had a chance to look over any of your logic yet. This is just syntax errors.
Dani the Computer Science Gal 
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds

Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
•
•
Join Date: Feb 2007
Posts: 20
Reputation:
Solved Threads: 0
•
•
•
•
Look at the lines where you have $x =, $y =, etc. Firstly, you are trying to set one variable equal to another, but you aren't putting dollar signs in front of all your variables. It should be$x = $hoursWorkedand not$x = hoursWorked. Also, you're setting $zz equal to $overtimeHours but that variable isn't set.
I haven't had a chance to look over any of your logic yet. This is just syntax errors.
Thanks and Blessings
•
•
Join Date: Jan 2007
Posts: 37
Reputation:
Solved Threads: 3
I've checked ur code and you seem to lack a lot of ";" at the end of your statements and the reason that the value of $payCheck is not displayed is because:
1) $_REQUEST["payCheck"] is empty
2) Your computation is not really a computation but a string that shows how the computation is done
3) Also when computing, the result is assigned as if it was assigning a value to a variable. it should be $z = $x * $y, not $x * $y = $z.
3) You're trying to printout the value of $paycheck when in fact it should be $payCheck, remember php variables are case sensitive
To solve your problem here's what you need to do:
1) correct your computation statement and assign the result to $paycheck
2) do not represent your computation as a string and don't enclose your strings in "(" and ")"
3) assign the result to a variable and output that variable in your echo statement
Other things to do:
1) remove these lines because the request data you are trying to get are never set therefore they are useless
2) The logic for your computation with overtime pay is kind of odd because you only compute for the overtimed hours when in fact it should be added to the wage for the normal hours worked.
Instead of "$z = $x - 40 * $y * 1.5", it should be "$z = ($x *$y) + (($x - 40) * $y * 1.5)". Where "($x * $y)" computes for the wage for regular hours worked and "(($x - 40) * $y * 1.5)" computes for the wage for overtime hours.
I debugged this locally and this is what I've done to make it work so there shouldn't be anymore problems. Cheers!
1) $_REQUEST["payCheck"] is empty
2) Your computation is not really a computation but a string that shows how the computation is done
3) Also when computing, the result is assigned as if it was assigning a value to a variable. it should be $z = $x * $y, not $x * $y = $z.
3) You're trying to printout the value of $paycheck when in fact it should be $payCheck, remember php variables are case sensitive
To solve your problem here's what you need to do:
1) correct your computation statement and assign the result to $paycheck
2) do not represent your computation as a string and don't enclose your strings in "(" and ")"
3) assign the result to a variable and output that variable in your echo statement
Other things to do:
1) remove these lines because the request data you are trying to get are never set therefore they are useless
PHP Syntax (Toggle Plain Text)
$pay = $_REQUEST["pay"] $payCheck = $_REQUEST["payCheck"]
Instead of "$z = $x - 40 * $y * 1.5", it should be "$z = ($x *$y) + (($x - 40) * $y * 1.5)". Where "($x * $y)" computes for the wage for regular hours worked and "(($x - 40) * $y * 1.5)" computes for the wage for overtime hours.
I debugged this locally and this is what I've done to make it work so there shouldn't be anymore problems. Cheers!
Last edited by jblacdao; Feb 27th, 2007 at 1:53 pm.
•
•
Join Date: Jan 2007
Posts: 37
Reputation:
Solved Threads: 3
•
•
•
•
HI jb
thanks it worked! I appreciate you taking the time and pointing out my mistakes. Even if I had the syntax correct, I knew I was leaving out something in my overtime.
regards
wavyaquaeyes
![]() |
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Display output on webpage
- Next Thread: site no.of visitors improving PHP
Views: 3816 | Replies: 8
| Thread Tools | Search this Thread |
Tag cloud for PHP
access ajax apache api array arrays beginner binary broken cakephp check checkbox class cms code combobox cron curl database date development directory display download dropdown dropdownlist echo email error file files form forms function functions google header hosting href htaccess html image include insert integration ip java javascript joomla jquery limit link list login mail menu methods mlm mod_rewrite multiple mysql oop parse password paypal php problem query random recursion regex results rewrite script search select server sessions sms soap sorting source sql storage structure syntax system table tutorial unicode update updates upload url validation variable video web xml youtube






