Help with $var['var'] type of variable.

Discussion in 'PHP' started by Dollar, Sep 7, 2009.

  1. #1
    How do you get the "variable" from inside this?

    Say you have

    $user['keldorn'] = "81dc9bdb52d04dc20036dbd8313ed055";
    PHP:
    I know how to get the md5 string. Simply

    $var = $user['keldorn'];
    PHP:

    But what if you do this?

    $var = $user[$username];
    PHP:


    Nothing happens. How do you extract the $username from inside that?

    I'm trying to do this comparing from a $_POST of username and password:

    if ( isset($user[$username]) && $user[$username] == md5($password) ) {
       // stuff
    }
    PHP:

    EDIT: Never mind. The answer just hit me like a ton of bricks. How embarrassing. :eek:

    
    $user['keldorn'] = "81dc9bdb52d04dc20036dbd8313ed055";
        if(!empty($_POST)) {
            $username =  $_POST['adminUsername'];
            $password  = $_POST['adminPassword'];
    
                if ( isset($user[$username]) && $user[$username] == md5($password) ) {
    			
    			echo "logged in";
    			exit;
    			
    			
    			
    			
    			
    			}
    
    			
    			
    	}
    PHP:
     
    Dollar, Sep 7, 2009 IP
  2. hamidof

    hamidof Peon

    Messages:
    619
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Don't worry about it, everyone starts somewhere, I made a lot of mistakes like this but I suggest reading a good book, it will make your life a lot easier and saves you tons of time and money.

    I suggest 'PHP & MySQL Web Development' by Luke Welling and Laura Thomson, it's an excellent beginner book and trust me you won't regret it ;)
     
    hamidof, Sep 7, 2009 IP