Im trying to retrieve the correct user_id for my user who is logging in to my website...
$result = $conn->prepare("SELECT * FROM users WHERE email_address= :em AND password= :pw");
$result->bindParam(':em', $user);
$result->bindParam(':pw', $password);
$result->execute();
$rows = $result->fetch(PDO::FETCH_NUM);
if($rows > 0) {
$_SESSION['loggedin'] = 1;
$_SESSION['uid'] = $rows['user_id'];
}
I want to get the relevant user_id and im trying to do so using $rows['user_id']; with no luck...
fetch()return? I think it's a result pointer rather than an array - you have to explicitly fetch the array. It also looks like you're returning ALL rows instead of just one, so$rows['user_id']would be undefined ($rows[0]['user_id']might work)PDO::FETCH_ASSOCinstead. "PDO::FETCH_NUM: returns an array indexed by column number as returned in your result set, starting at column 0" php.net/manual/en/pdostatement.fetch.php