How to resolve an 'Undefined Index' error?
<p>Following is my code. I get an <code>undefined index error</code> when the validation is completed and about to populate the 'Success' message.</p>

<p>I have digged and identified where the problem is (<code>&lt;td&gt;&lt;?= $errors['fname'] ?&gt;&lt;/td&gt;</code>) but what I don't understand is what is the correct method of defining the index which resulted the error. Can someone highlight where I've gone wrong? Thanks.</p>

<pre><code>            &lt;?php
        function VerifyForm(&amp;$values, &amp;$errors)
        {
        if($values['fname'] == "")
        {$errors['fname'] = 'empty';} 
        }
        function DisplayForm($values, $errors)
        {
        ?&gt;
        &lt;html&gt;
        &lt;head&gt;
        &lt;title&gt;Register&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
        &lt;form action="&lt;?= $_SERVER['PHP_SELF'] ?&gt;" method="POST"&gt;
        &lt;table border="1"&gt;
        &lt;tr&gt;
        &lt;td&gt;First Name :&lt;/td&gt;
        &lt;td&gt;&lt;input type="text" name="fname" value="&lt;?= htmlentities($values['fname']) ?&gt;"/&gt;
        &lt;td&gt;&lt;?= $errors['fname'] ?&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;&lt;td colspan="2" align="center"&gt;&lt;input type="submit" value="Submit"&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;/table&gt;
        &lt;/form&gt;
        &lt;/body&gt;
        &lt;/html&gt;
        &lt;?php
        }
        function ProcessForm($values)
        {
        echo ("&lt;p&gt;Your record has been successfully added!&lt;/p&gt;");
        }
        if ($_SERVER['REQUEST_METHOD'] == 'POST')
        {
        $formValues = $_POST;
        $formErrors = array();

        if (!VerifyForm($formValues, $formErrors))
        DisplayForm($formValues, $formErrors);
        else
        ProcessForm($formValues);
        }
        else
        DisplayForm(null, null);
        ?&gt;
</code></pre>
