How do I get the username of the logged-in user?
You can use the global $user object:

An object representing the user currently visiting the site.
Contains preferences and other account information for logged-in users. When a user is not logged-in, the $user-&gt;uid property is set to 0.

e.g.
global $user;
$name = $user-&gt;name;
$id = $user-&gt;uid;

// or
$name = $GLOBALS['user']-&gt;name;
$id = $GLOBALS['user']-&gt;uid;