尝试使用MySQL返回用户信息

Current code:

<?php

session_start();

if ($_SESSION['username']) {
    echo "Signed in as " . "$_SESSION[username]" . "<br />" . "<a href='logout.php'>Log         out</a>";

    //Get user info.

    $results = mysql_query("SELECT * FROM users WHERE username=$_SESSION[username]");
    while($row = mysql_fetch_array($results) {
        $db_username = $row['username'];
        echo $db_username;
    }
}    

else {
    echo "Log in";
}

?>

Unfortunately I'm getting errors when returning the values that MySQL is supposed to be getting. Any idea why?

You forgot to use single quote around value in query

mysql_query("SELECT * FROM users WHERE username='{$_SESSION[username]}'");
                                                ^^                   ^^ 

Also stop using mysql_* functions they are deprecated, Use MySQLi OR PDO.

Your query is wrong since it contains PHP variables not enclosed in single quotes or curly braces. You can rewrite the query as follows:

With braces:

$results = mysql_query("SELECT * FROM users WHERE username={$_SESSION[username]}");`

Or with single quotes:

$results = mysql_query("SELECT * FROM users WHERE username='$_SESSION[username]'");