bambinou1980 Posted July 16, 2015 Share Posted July 16, 2015 Hello, I have this code here: while ($row = mysqli_fetch_row($results)) { //If Admin name = md5 mysql recorded version if (md5($password) == $row[2]) { echo "All good!"; }else{ echo "wrong username/password!"; } I would like to use $row['password']; in stead of $row[2] but it is not working, I am worried to one day have the array 2 changing position and would prefer use the actual column name instead, how do to this please? My column name is "password". Thank you, Ben Quote Link to comment https://forums.phpfreaks.com/topic/297328-how-to-use-database-column-name-rather-than-array-position/ Share on other sites More sharing options...
cyberRobot Posted July 16, 2015 Share Posted July 16, 2015 You can use mysqli_fetch_assoc() instead of row: http://php.net/manual/en/mysqli-result.fetch-assoc.php Quote Link to comment https://forums.phpfreaks.com/topic/297328-how-to-use-database-column-name-rather-than-array-position/#findComment-1516561 Share on other sites More sharing options...
scootstah Posted July 16, 2015 Share Posted July 16, 2015 You should not be using MD5() to store passwords. Use a proper password hashing algorithm like bcrypt or password_hash. Quote Link to comment https://forums.phpfreaks.com/topic/297328-how-to-use-database-column-name-rather-than-array-position/#findComment-1516568 Share on other sites More sharing options...
cyberRobot Posted July 16, 2015 Share Posted July 16, 2015 For what it's worth, here some more information about password hashing: http://php.net/manual/en/faq.passwords.php Quote Link to comment https://forums.phpfreaks.com/topic/297328-how-to-use-database-column-name-rather-than-array-position/#findComment-1516570 Share on other sites More sharing options...
Barand Posted July 16, 2015 Share Posted July 16, 2015 If the position of the password column may be a problem in future then it sounds like your query is using "SELECT * ". Don't. Specify the required columns. If you had, say, "SELECT id, username, password" it would not matter what the order of columns is in the table (so long as you don't actually drop any the used columns) Quote Link to comment https://forums.phpfreaks.com/topic/297328-how-to-use-database-column-name-rather-than-array-position/#findComment-1516578 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.