When the user logs in, you can set a session variable to the username they used. That or after you authenticate them, pull the username from their record and store it in the $_SESSION variable. Then whenever you need access to the user's name, you can use this variable in the query.
Lets say after they logged in and you verified who they were, you would set $_SESSION['user'] to their username they used during login.
Then on this page you can access it like so...
php
// Get the session variable and put it in a variable called $user
$user = $_SESSION["user"];
$result = mysql_query("SELECT * FROM users WHERE username='$user'") or die(mysql_error());
$row = mysql_fetch_array($result); // gets the data from username ahmed - i want this to be for whatever username is signed in
$oldoil = $row['oil']; // the originally amount of oil they had
$oil = $_POST['oil']; // the oil they're buying
$newoil = $oil+$oldoil; // the oil they're going to have in total
$sql = "UPDATE users SET oil = $newoil WHERE username='$user'";
mysql_query($sql)or die(mysql_error());
echo "You now have ".$newoil." barrels after purchasing ".$oil;
See how we pulled out their username from the session, stored it in $user and then used $user in the two queries?
Hope that helps you out.
"At DIC we be pulling usernames from sessions type of code ninjas...we also pull teeth, hair, and sometimes on rare occasions fingers."