Codarz360 Posted January 12, 2011 Share Posted January 12, 2011 Alright, I have created a hash password checker and here is my code: include("include.php"); // include the mySQL info! $users = mysql_query(" SELECT * FROM User "); // Select all from the users table in the database! while($row = mysql_fetch_array($users)) // While it fetches the users do the following... { if (hash("sha256", $password) == $row["Password"]) echo "Congratulations! The Hash matches the password entered into the database!"; } elseif (hash("sha256", $password) != $row["Password"]) { echo "Your Hash failed to match the password entered!"; } Now for some reason this displays a totally blank page. When I turn error display on I get the error "Unexpected T_ELSEIF" on this line elseif (hash("sha256", $password) != $row["Password"]) Any help is appreciated... Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/ Share on other sites More sharing options...
fxuser Posted January 12, 2011 Share Posted January 12, 2011 what if you dont use the elseif and just use else{ //do stuff } Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158264 Share on other sites More sharing options...
Codarz360 Posted January 12, 2011 Author Share Posted January 12, 2011 Then I get the error "Unexpected T_ELSE" or if I turned the display errors off I would still be presented with a blank page. Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158265 Share on other sites More sharing options...
revraz Posted January 12, 2011 Share Posted January 12, 2011 You are missing a { after IF Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158267 Share on other sites More sharing options...
mikecampbell Posted January 12, 2011 Share Posted January 12, 2011 You're missing a { after this line: if (hash("sha256", $password) == $row["Password"]) And you're missing the } to close your while loop. Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158268 Share on other sites More sharing options...
Codarz360 Posted January 12, 2011 Author Share Posted January 12, 2011 Alright so your saying it should look like this now: include("include.php"); // include the mySQL info! $users = mysql_query(" SELECT * FROM User "); // Select all from the users table in the database! while($row = mysql_fetch_array($users)) // While it fetches the users do the following... { if (hash("sha256", $password) == $row["Password"]) // If the hash matches the password echo the following... { echo "Hash correct!"; } elseif (hash("sha256", $password) != $row["Password"]) { echo "Your Hash failed to match the password entered!"; } else die("Nothing"); } If so then all this is doing is displaying "Your Hash failed to match the password entered!" when I know for a fact it's the correct hash for the password. Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158269 Share on other sites More sharing options...
fxuser Posted January 12, 2011 Share Posted January 12, 2011 in your database is password column named Password or password? try changing $row["Password"] to $row["password"] Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158270 Share on other sites More sharing options...
Codarz360 Posted January 12, 2011 Author Share Posted January 12, 2011 My database column is named "Password" so it should match up but for some reason it doesn't. Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158272 Share on other sites More sharing options...
Codarz360 Posted January 12, 2011 Author Share Posted January 12, 2011 I think I have fixed the original error by putting the code I had in my checkpass.php into my adduser.php script. The only problem I'm having now is I'm getting notices from the PHP error system saying that I have 2 "Undefined variables" any idea's how to solve this small issue without turning off the display errors? Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158307 Share on other sites More sharing options...
revraz Posted January 12, 2011 Share Posted January 12, 2011 Sure, define your variables. Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158310 Share on other sites More sharing options...
Codarz360 Posted January 12, 2011 Author Share Posted January 12, 2011 Yes I know I need to do that but how exactly would I go about it? Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158341 Share on other sites More sharing options...
BlueSkyIS Posted January 12, 2011 Share Posted January 12, 2011 here is an example of defining the variable $somevar: $somevar = ''; Quote Link to comment https://forums.phpfreaks.com/topic/224159-hash-password-checker-unexpected-t_elseif-error/#findComment-1158406 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.