Question: I have the following snippet of code. When I check how many rows the results array has, it prints out 1. But when I try to access the data within (firstname, lastname, username, etc.) it prints nothing out.

```
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);

$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);

if (mysqli_num_rows($results) == 1) {
    $session_user = mysqli_fetch_assoc($result);

    $_SESSION['firstname'] = $session_user['firstname'];
    $_SESSION['lastname'] = $session_user['lastname'];
    echo $_SESSION['firstname']; // doesn't print anything

    $_SESSION['username'] = $username;
    $_SESSION['success'] = true;

    header('location: index.php');
}

```

The MYSQL database however shows that the data is there, and the column name is indeed correct, order being: id, username, firstname, lastname, email, password.

I am lost, what am I doing wrong here?

Answer: 
You are calling a wrong variable `$result` instead of `$results` in your `mysqli_fetch_assoc` function.
may be this will work.

```
if (mysqli_num_rows($results) > 0) {
    $session_user = mysqli_fetch_assoc($result);

    $_SESSION['firstname'] = $session_user['firstname'];
    $_SESSION['lastname'] = $session_user['lastname'];
    echo $_SESSION['firstname']; // doesn't print anything

    $_SESSION['username'] = $username;
    $_SESSION['success'] = true;

    header('location: index.php');
}

```