PHP - Undefined variable
<p>I'm new to PHP.</p>

<p>Currently in 'tutorials stage'.
I'm doing some exercises from Beginners PHP &amp; MySQL by Mr. Tucker.
On his example everything works fine,  but on my PC there is an error: </p>

<p><code>Notice: Undefined index: username in C:\wamp\www\form\loginForm.php on line 21</code></p>

<p>Full PHP code for this example: </p>

<ul>
<li>please note table does exist, password, connection to the DB
etc...are correct</li>
<li><p>I know that <code>$username</code> if define when the form is submitted, but in provided tutorial there is no error</p>

<p>

<pre><code>{       //  Secure Connection Script
    include('../htconfig/dbConfig.php'); 
    $dbSuccess = false;
    $dbConnected = mysql_connect($db['hostname'],$db['username'],$db['password']);

    if ($dbConnected) {     
        $dbSelected = mysql_select_db($db['database'],$dbConnected);
        if ($dbSelected) {
            $dbSuccess = true;
        }   
    }
    //  END Secure Connection Script
}

$thisScriptName = "loginForm.php";  

$username = $_POST['username']; 
if(isset($username)) {

    $password = $_POST['password'];
    $md5Password = md5($password);


    {   //      SELECT password for this user from the DB and see it it matches 
        $tUser_SQLselect = "SELECT password FROM tUser ";
        $tUser_SQLselect .= "WHERE email = '".$username."' ";   

        $tUser_SQLselect_Query = mysql_query($tUser_SQLselect);     

        //$passwordRetrieved = "";          
        while ($row = mysql_fetch_array($tUser_SQLselect_Query, MYSQL_ASSOC)) {
            $passwordRetrieved = $row['password'];
        }
        mysql_free_result($tUser_SQLselect_Query);

        if (!empty($passwordRetrieved) AND ($md5Password == $passwordRetrieved)) {
                //header("Location: ../index.php?auth=1");  // if logged redirect to
                            echo '&lt;form name="authForm" action="../index.php" method="post"&gt;';  
                            echo '
                                &lt;input type="hidden" name="auth" value="1" /&gt;
                                Password OK:                                    
                                &lt;input type="submit"  value="Click to Proceed" /&gt;
                            ';
                    echo '&lt;/form&gt;';

        } else {
            echo "Access denied.&lt;br /&gt;&lt;br /&gt;";      
            echo '&lt;a href="'.$thisScriptName.'"&gt;Try again&lt;/a&gt;';         
        }
    }

} else {
    echo '&lt;h2&gt;Login Form &lt;/h2&gt;';
    echo '&lt;form name="postLoginHid" action="'.$thisScriptName.'" method="post"&gt;';   
            echo '
                &lt;P&gt;User name: 
                &lt;INPUT TYPE=text NAME=username value=""&gt;&lt;/P&gt;
                &lt;P&gt;Password: 
                &lt;INPUT TYPE=password NAME=password value=""&gt;&lt;/P&gt;
                &lt;input type="submit"  value="Login" /&gt;
            ';
    echo '&lt;/form&gt;';

}

 echo '&lt;h2&gt;--------- END Login Form --------&lt;/h2&gt;';

 ?&gt;
</code></pre></li>
</ul>
