mysql_query
returns a resource. The returned result resource should be passed to mysql_fetch_array()
, and other functions for dealing with result tables, to access the returned data.
$result = mysql_query("SELECT id FROM account WHERE username='".$username."' LIMIT 1") or die(mysql_error);
while ($row = mysql_fetch_assoc($result))
{
$_SESSION['id'] = $row['id'] ;
}
echo ("ID: ".$_SESSION["id"]."");
As a sidenote, the query is vulnerable with SQL Injection
if the value(s) of the variables came from the outside. Please take a look at the article below to learn how to prevent from it. By using PreparedStatements
you can get rid of using single quotes around values.