1.11M Members

My script needs help-Calculate a Paycheck

 
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:

<!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

 
0
 

Where are you having problems?

 
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.

 
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 = $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.

 
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 = $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:sad:

 
0
 

Refer to my next post, I accidentally submitted my reply twice. Sorry

 
1
 

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

$pay = $_REQUEST["pay"]
$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!

 
0
 

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

 
0
 

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 ;)

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article