My script needs help-Calculate a Paycheck

Reply

Join Date: Feb 2007
Posts: 20
Reputation: wavyaquaeyes is an unknown quantity at this point 
Solved Threads: 0
wavyaquaeyes wavyaquaeyes is offline Offline
Newbie Poster

My script needs help-Calculate a Paycheck

 
0
  #1
Feb 25th, 2007
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:
  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
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,422
Reputation: stymiee is on a distinguished road 
Solved Threads: 35
Moderator
stymiee's Avatar
stymiee stymiee is offline Offline
He's No Good To Me Dead

Re: My script needs help-Calculate a Paycheck

 
0
  #2
Feb 25th, 2007
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!
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 20
Reputation: wavyaquaeyes is an unknown quantity at this point 
Solved Threads: 0
wavyaquaeyes wavyaquaeyes is offline Offline
Newbie Poster

Re: My script needs help-Calculate a Paycheck

 
0
  #3
Feb 25th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,096
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 131
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: My script needs help-Calculate a Paycheck

 
0
  #4
Feb 25th, 2007
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.
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 20
Reputation: wavyaquaeyes is an unknown quantity at this point 
Solved Threads: 0
wavyaquaeyes wavyaquaeyes is offline Offline
Newbie Poster

Re: My script needs help-Calculate a Paycheck

 
0
  #5
Feb 25th, 2007
Originally Posted by cscgal View Post
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 37
Reputation: jblacdao is an unknown quantity at this point 
Solved Threads: 3
jblacdao jblacdao is offline Offline
Light Poster

Re: My script needs help-Calculate a Paycheck

 
0
  #6
Feb 27th, 2007
Refer to my next post, I accidentally submitted my reply twice. Sorry
Last edited by jblacdao; Feb 27th, 2007 at 1:52 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 37
Reputation: jblacdao is an unknown quantity at this point 
Solved Threads: 3
jblacdao jblacdao is offline Offline
Light Poster

Re: My script needs help-Calculate a Paycheck

 
1
  #7
Feb 27th, 2007
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
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 20
Reputation: wavyaquaeyes is an unknown quantity at this point 
Solved Threads: 0
wavyaquaeyes wavyaquaeyes is offline Offline
Newbie Poster

Re: My script needs help-Calculate a Paycheck

 
0
  #8
Mar 1st, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 37
Reputation: jblacdao is an unknown quantity at this point 
Solved Threads: 3
jblacdao jblacdao is offline Offline
Light Poster

Re: My script needs help-Calculate a Paycheck

 
0
  #9
Mar 2nd, 2007
Originally Posted by wavyaquaeyes View Post
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 3816 | Replies: 8
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC