Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - Undefined variable
    text
    copied!<p>I'm new to PHP.</p> <p>Currently in 'tutorials stage'.</p> <p>I'm doing some exercises from Beginners PHP &amp; MySQL by Mr. Tucker.</p> <p>On his example everything works fine, but on my PC there is an error: </p> <p><code>Notice: Undefined variable: passwordRetrieved in C:\wamp\www\loginForm.php on line 39</code>.</p> <p>Full PHP code for this example: - please note table does exist, password, connection to the DB etc... are correct</p> <pre><code>&lt;?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 '&lt;h2&gt;Login Form &lt;/h2&gt;'; $username = $_POST['username']; if(isset($username)) { $password = $_POST['password']; echo "username = ".$username."&lt;br /&gt;"; echo "password = ".$password."&lt;br /&gt;"; { // 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."&lt;br /&gt;"; if (!empty($passwordRetrieved) AND ($password == $passwordRetrieved)) { echo "YES. Password matches.&lt;br /&gt;&lt;br /&gt;"; echo '&lt;a href="'.$thisScriptName.'"&gt;Logout&lt;/a&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;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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload