943,828 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 4499
  • PHP RSS
Feb 25th, 2007
0

My script needs help-Calculate a Paycheck

Expand Post »
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:
php Syntax (Toggle Plain Text)
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3.  
  4. <html>
  5. <head>
  6. <title>Calculate Your PayCheck</title>
  7. </head>
  8. <body>
  9. <h1>Calculate Your Paycheck</h1>
  10.  
  11. <form method = "post"
  12. action = "Paycheck.php">
  13.  
  14.  
  15. <table border = 1>
  16. <tr>
  17. <th>Hours Worked
  18. <input type = "integer"
  19. name = "hoursWorked"
  20. value = "">
  21.  
  22. </th>
  23. </tr>
  24.  
  25. <tr>
  26. <th>Wages
  27. <input type = "integer"
  28. name = "wages"
  29. value = "">
  30.  
  31. </th>
  32. </tr>
  33.  
  34.  
  35. <tr>
  36. <td colspan = 2>
  37. <center>
  38. <input type = "Submit"
  39. value = "Submit">
  40. </center>
  41. </td>
  42. </tr>
  43. </table>
  44.  
  45.  
  46.  
  47. <?PHP
  48. $hoursWorked = $_REQUEST["hoursWorked"]
  49. $wages = $_REQUEST["wages"]
  50. $pay = $_REQUEST["pay"]
  51. $payCheck = $_REQUEST["payCheck"]
  52.  
  53. $x = hoursWorked;
  54. $y = wages;
  55. $z = pay;
  56. $zz = overtimeHours;
  57.  
  58. if ($x is <= 40){
  59. $submit = ("$x * $y = $z")
  60. echo "Your Paycheck is: $paycheck";
  61. }
  62. if ($x is > 40){
  63. $submit = ("$x - 40 * $y * 1.5 =$z")
  64. echo "Your Paycheck is: $paycheck";
  65. }
  66. ?>
  67.  
  68. </center>
  69. </form>
  70. </body>
  71. </html>



Thanks
Last edited by stymiee; Feb 25th, 2007 at 11:59 am. Reason: added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wavyaquaeyes is offline Offline
20 posts
since Feb 2007
Feb 25th, 2007
0

Re: My script needs help-Calculate a Paycheck

Where are you having problems?
Moderator
Reputation Points: 161
Solved Threads: 38
He's No Good To Me Dead
stymiee is offline Offline
1,422 posts
since May 2006
Feb 25th, 2007
0

Re: My script needs help-Calculate a Paycheck

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wavyaquaeyes is offline Offline
20 posts
since Feb 2007
Feb 25th, 2007
0

Re: My script needs help-Calculate a Paycheck

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 = $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.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Feb 25th, 2007
0

Re: My script needs help-Calculate a Paycheck

Click to Expand / Collapse  Quote originally posted by cscgal ...
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 = $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.
HI I hope you can look over my logic. The book I have does not show that. At this point Im very frustrated. Please understand I am not trying to have someone do my work for me....its just I dont see where my mistakes are. I did correct what you said above, but am still showing the code and it does not give me the result of the paycheck.

Thanks and Blessings
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wavyaquaeyes is offline Offline
20 posts
since Feb 2007
Feb 27th, 2007
0

Re: My script needs help-Calculate a Paycheck

Refer to my next post, I accidentally submitted my reply twice. Sorry
Last edited by jblacdao; Feb 27th, 2007 at 1:52 pm.
Reputation Points: 12
Solved Threads: 3
Light Poster
jblacdao is offline Offline
37 posts
since Jan 2007
Feb 27th, 2007
1

Re: My script needs help-Calculate a Paycheck

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
PHP Syntax (Toggle Plain Text)
  1. $pay = $_REQUEST["pay"]
  2. $payCheck = $_REQUEST["payCheck"]
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!
Last edited by jblacdao; Feb 27th, 2007 at 1:53 pm.
Reputation Points: 12
Solved Threads: 3
Light Poster
jblacdao is offline Offline
37 posts
since Jan 2007
Mar 1st, 2007
0

Re: My script needs help-Calculate a Paycheck

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
wavyaquaeyes is offline Offline
20 posts
since Feb 2007
Mar 2nd, 2007
0

Re: My script needs help-Calculate a Paycheck

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
no problem, it was my pleasure helping you out :cheesy: don't hesitate to ask help if you need it, I'm always open for it
Reputation Points: 12
Solved Threads: 3
Light Poster
jblacdao is offline Offline
37 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP for application/software development
Next Thread in PHP Forum Timeline: site no.of visitors improving PHP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC