I'm doing some exercises from Beginners PHP & MySQL by Mr. Tucker.
On his example everything works fine, but on my PC there is an error:
Notice: Undefined variable: passwordRetrieved in C:\wamp\www\loginForm.php on line 39
Full PHP code for this example:
Please note the table does exist, and password, connection to the DB, etc... are correct
<?php { // 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"; echo '<h2>Login Form </h2>'; $username = $_POST['username']; if(isset($username)) { $password = $_POST['password']; echo "username = " . $username . "<br />"; echo "password = " . $password . "<br />"; { // SELECT password for this user from the DB and see it it matches $tUser_SQLselect = "SELECT password FROM tUser "; $tUser_SQLselect .= "WHERE username = '" . $username . "' "; $tUser_SQLselect_Query = mysql_query($tUser_SQLselect); while ($row = mysql_fetch_array($tUser_SQLselect_Query, MYSQL_ASSOC)) { $passwordRetrieved = $row['password']; } mysql_free_result($tUser_SQLselect_Query); echo "passwordRetrieved = ".$passwordRetrieved."<br />"; if (!empty($passwordRetrieved) AND ($password == $passwordRetrieved)) { echo "YES. Password matches.<br /><br />"; echo '<a href="' . $thisScriptName . '">Logout</a>'; } else { echo "Access denied.<br /><br />"; echo '<a href="' . $thisScriptName . '">Try again</a>'; } } } else { echo '<form name="postLoginHid" action="' . $thisScriptName . '" method="post">'; echo ' <P>User name: <INPUT TYPE=text NAME=username value=""></P> <P>Password: <INPUT TYPE=password NAME=password value=""></P> <input type="submit" value="Login" /> '; echo '</form>'; } echo '<h2>--------- END Login Form --------</h2>'; ?>