Jump to content

How to use database column name rather than array position?


bambinou1980

Recommended Posts

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

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.