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.

I think the 'wages' the error message refers to is the $_POST['wages']. The key ('wages'), as the error states, does not exist in the $_POST array.

<?php
$errorcount=0;

//add the following line to see if the $_POST array exists and what it contains.
print_r($_POST);

$wages=$_POST['wages'];
$hours=$_POST['hours'];

It is just a warning that at the time your variables have no values.

Try moving this

$wages=$_POST['wages'];
$hours=$_POST['hours'];

Into your if statement

if (isset($_POST['submit']))
    { 
    $wages=$_POST['wages'];
    $hours=$_POST['hours'];

Also print_r($_POST) to check that you are receiving values through your form post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.