if (regex("[A-Za-z0-9_]{1,}",$username){
//do something
}else{
echo "login failed";
}
see {man]regex[/man] for more detail
the above regex (i hope) looks to give a true or false on any string that is alpha or numeric or has an underscore of at least one letter...
you should probably adapt your code to ask for username and login as opposed to username and id as you have seen it is easy to get around
other options include
if((empty($id) || empty($username)||($username==' '))
can also stipulate min length for username
username of a certain type - all alpha / all numeric etc
hth