从会话中获取用户数据

I made a login system and it works but I also have the user's session in the page after login.

How can I get user data from my database by referencing the user's session, and how can I update it when the user put what they going to change

<?php   
session_start();                        
$query=mysql_query("SELECT username, email, password FROM user WHERE  username = $_SESSION['username']");
 while($row = mysql_fetch_array( $query )) {

 echo .row['username'];
 echo .row['email'];
 echo .row ['password'];

 ?>

In new codes you should be using mysqli if your PHP version is high enough (if not... update...)

But here you go:

<?php   
session_start();                        
$query = mysql_query("SELECT * FROM user WHERE  username = {$_SESSION['username']}");
 $row = mysql_fetch_assoc($query);

 echo $row['username'];
 echo $row['email'];
 echo $row ['password'];

 ?>

Oh and the update:

<?php
$query = mysql_query("UPDATE user SET username={$_POST['username']}, email={$_POST['email']}, password={$_POST['password']} WHERE username={$_SESSION['username']}");
?>

And you should make a form for that..

The answer of Cris is almost perfect and well explained. But it is missing the quotes for the string in the statement.

As the col username will most likely be a varchar of any length.

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