Any data being used in the query needs to be sanitized, even if it's not actually stored in the database. Your function looks reasonable to me.
However, this line looks a little confused:
$_SESSION['username'] = 1;
Instead of 1, perhaps it should be $username?