Getting a undefined variable for mysql variable

So I’m not fully sure what my issue is, I’m trying to pull information from a users account off of my mysql like a username, yet I get an undefined variable for “row”. I’ve done this before and for some reason can’t get it to work.

if(isset($_GET[‘userId’]) && $_GET[‘userId’] != ‘’){

$query = "SELECT * FROM login WHERE id = '".$_SESSION['userid']."'";

$row= $con->query($query);

}

I would use prepared statements even for the this and I would also use PDO.

Here’s a small of example of a login script that I made

    $query = 'SELECT * FROM members WHERE id=:id';


    $stmt = $pdo->prepare($query); // Prepare the query:
    $stmt->execute([':id' => $id]); // Execute the query with the supplied user's id:

I also don’t understand or a little confused that you check $_GET[‘userId’] is set, but use $_SESSION[‘userid’]? What happens if they are not the same?

I would guess that the query fails and is returning false. Follow Striders comments for a better route than your current.

Sponsor our Newsletter | Privacy Policy | Terms of Service