#1
  1. Plays with fire
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    942
    Rep Power
    96

    Not sure why this isn't working -- PDO


    Trying to make a simple login system in two steps.

    The first step just checks for matching username/passwords.

    If there's a match, then grab the user credentials from another table. The first query works fine, the second not so much:

    Code:
    // check for match
    		$sth = $dbh->prepare("SELECT fname, group_name, pkey FROM [table] WHERE email=? AND password=?");
    		$sth->execute(array($email,$pass));
    		
    		if ($sth->rowCount()<1) {
    			$fail=1;
    		} else {
    			// get user info
    			$info=$sth->fetch(PDO::FETCH_ASSOC);
    			$_SESSION['un']=$info['fname'];
    			$_SESSION['ug']=$info['group_name'];
    			$key=$info['pkey'];
    			
    			if ($info['group_name']=="Admin") {
    				$_SESSION['um']="all";
    			} else {
    				//get menus
    				$sth=$dbh->prepare("SELECT GROUP_CONCAT(menu_key ORDER BY menu_key SEPARATOR '~') AS menus FROM [table2] WHERE people_key=?");
    				$sth=execute(array($key));
    				$m=$sth->fetch(PDO::FETCH_ASSOC);
    				
    				$menus=$m['menus']
    echo $menus;
    			}
             }
    both queries work fine in phpmyadmin, but I'm not getting anything with the second when I know I should. I originally combined these queries to get all the info at once, but the problem was if the people_key didn't exist in the admin_creds table nothing was returned.

    Any ideas?
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence
  2. #2
  3. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,932
    Rep Power
    4033
    Originally Posted by Frank Grimes
    Code:
    				$sth=execute(array($key));
    You want ->, not =
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  4. #3
  5. Plays with fire
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2003
    Location
    Barsoom
    Posts
    942
    Rep Power
    96
    hahaha. I'm such an idiot. That'll teach me to have a vacation.

    thank you!
    “Be ashamed to die until you have won some victory for humanity.” -- Horace Mann

    "...all men are created equal." -- US Declaration of Independence

IMN logo majestic logo threadwatch logo seochat tools logo