I am very new to PHP. Right now we are working with functions and control structures. I have an assignment where I have to calculate earnings based on wage, hours, and potential overtime over 40 hours at 1.5.

There are no examples in my text at this point that I can follow from for direction and at this point I am going blind.

Can someone please provide assistance or direction on what I should be doing? As of now, all I am getting are errors.

paycheck.html code:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Paycheck Calculator</title>
<meta http-equiv="Content-Type"
	content="text/html; charset=iso-8859-1" />
</head>
<body>
	<table>
    <tr>
    </tr>
    <tr>
        <td><h1>Paycheck Calculator</h1></td>
    </tr>
    <tr>


</tr>
</table>
<hr />

<form method="get" action="Paycheck.php">
    <p>Hours worked:
    <input type="text" name="hours" id="hours" />
    </p>
    <p>Employee wage:
    <input type="text" name="wage" id="wage" /><br /><br />
    <input type="submit" />
    </p>

</form>
</body>
</html>

paycheck.php code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Paycheck Results</title>
<meta http-equiv="Content-Type"
	content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="php_styles.css" type="text/css" />
</head>
<body>
<h1>Paycheck Calculations</h1>
<?php

$hoursWorked = $_GET["hours"];
$wages = $_GET["wage"];
$x = $hoursWorked;
$y = $wages;
$z = $pay;

if ($x is <= 40){
$submit = ("$z = $x * $y")
echo "Your Paycheck is: $payCheck";
}

if ($x is > 40){
$submit = ("$z = ($x *$y) + (($x - 40) * $y * 1.5")
echo "Your Paycheck is: $payCheck";
}

?>
</body>
</html>

Any assistance would be greatly appreciated.

    In the two IF conditions, get rid of the word "is" before the comparison operators. Also, in the code that follows each condition, you forgot the ";" at the end of the lines where you do your arithmetic.

    PS: You can make your PHP code easier to read here by wrapping it in [noparse]

    ...

    tags (instead of

    )[/noparse], as they add contextual colored highlighting.
      5 days later

      Cool project. try to keep things simple and learn some of the globally used maths functions like max, min, abs... etc. Just about every language has these basic functions, so learning these will do you good for the future.

      <html><head><title>Paycheck Results</title></head>
      <body>
      <h1>Paycheck Calculations</h1>
      
      <?php
      $hours = (int) $_GET["hours"];
      $wages = (int) $_GET["wage"];
      
      $overtime = max($hours - 40, 0);
      $pay += $overtime * $wages * 1.5;
      $pay += ($hours - $overtime) * $wages;
      
      echo "Hours Worked: " . $hours . "<br>";
      echo "Pay rate (per hour): $" . number_format($wages, 2) . "<br>";
      echo "Overtime Hours: " . $overtime . "<br>";
      echo "Your Paycheck is: $" . number_format($pay, 2) . "<br>";
      ?>
      </body>
      </html>
        Write a Reply...