I cant for the life of me understand why I get this error:
Undefined index: wages in F:\EasyPHP-5.3.2i\www\PaycheckCalc.php on line 13
line 13 is: $wages=$_POST['wages'];
I also get this for the following line.
this is the 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>
<?php
$errorcount=0;
$wages=$_POST['wages'];
$hours=$_POST['hours'];
if (isset($_POST['submit']))
{ //begins if1//
//echo "<p>The submit button has been pressed.</p>\n";
if (is_numeric($wages))
{//begins if #2
if ($wages >0)
{//begins if #3
$weekly_wages = $wages;
}//ends if #3
else
{//goes with if #3
++$errorcount;
echo "<p>Weekly wage must to be greater than 0</p>";
}//ends else #3
}//ends if #2
else
{//goes with if #2
++$errorcount;
echo "<p>You must enter a number for the wage</p>\n";
//echo "<p>Error Count: " . $errorcount . "</p>\n";
}//ends else #2
} //closes if#1 wage isset
if (isset($_POST['submit']))
{ //begins if1//
//echo "<p>The submit button has been pressed.</p>\n";
if (is_numeric($hours))
{//begins if #1 hours
if($wages >= 0)
{//begins if #2
if ($hours > 40)
{//begins if #3
$bonus = true;
echo "<p>Overtime: " . $bonus . "</p>\n";
}//ends if #3
}//ends if #2
else
{//begins else #2
++$errorcount;
echo "<p>The number of hours must be 0 or higher</p>\n";
}//ends if #2
}//ends if #1
else
{//begins else #1
++$errorcount;
echo "<p>The value for hours must be a number</p>\n";
}//ends else #1
} //closes if#1 isset submit
$ot_amt = 0;
if ($errorcount == 0 && isset($_POST['submit']))
{//begins if calculations
if ($hours > 40)
{
$ot_amt = (($hours - 40) * ($wages * 1.5));
$weekly_pay = ($hours * $wages) ;
}
else
{
$weekly_pay = ($hours * $wages) ;
}
//$weekly_pay = $weekly_wages + $bonus_amt;
echo "<p>Weekly Salary= $" . number_format($weekly_pay, 2) . ".</p>\n";
echo "<p>Overtime Pay = $" . number_format($ot_amt, 2) . ".</p>\n";
echo "<p>Your total Weekly Pay is $" . number_format($weekly_pay + $ot_amt, 2) . ".</p>\n";
echo "<p><a href = 'PaycheckCalc.html'>Calculate another paycheck?</a></p>\n";
}//ends if 1//
else
{//begins else for calculation
?>
<h2 style="text-align:center">Paycheck Calculation</h2>
<form action=
"PaycheckCalc.php" method="post">
<p>Weekly Wage: <input type="text" name="wages" /></p>
<p>Number of Hours Worked: <input type="text" name="hours" /></p>
<p><input type="submit" name="submit" value="Submit"></p>
</form>
<?php
}//ends else to display form
?>
</body>
</html>
Can someone please give me an explaination of why this is happening and how to fix it. Thank you.