PHP - Undefined variable

后端 未结 9 747
星月不相逢
星月不相逢 2021-01-26 05:29

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:

相关标签:
9条回答
  • 2021-01-26 06:05

    Just before while where you set variable $passwordRetrieved declare it so it should look like this:

    $tUser_SQLselect_Query = mysql_query($tUser_SQLselect);
    $passwordRetrieved = "";
    
    
    while ($row = mysql_fetch_array($tUser_SQLselect_Query, MYSQL_ASSOC)) {
        $passwordRetrieved = $row['password'];
    }
    
    0 讨论(0)
  • 2021-01-26 06:07

    As this question has already been answered, I would also add instead of using mysql_fetch_array with the MYSQL_ASSOC parameter, you can just use mysql_fetch_assoc() :)

    0 讨论(0)
  • 2021-01-26 06:09

    If your query returned no results, then $passwordRetrieved is undefined (just like the message says).

    You should throw an error when you couldn't find any users with username=$username (which is also an invalid login).

    0 讨论(0)
提交回复
热议问题