The if statement is not a loop 😉.
This needs some change:
if($_SESSION[userid]==$rowmem['userid'] && $_SESSION['username']==$rowmem['username'])
try this:
if(!empty($_SESSION['userid'], $_SESSION['username']) && $_SESSION[userid]==$rowmem['userid'] && $_SESSION['username']==$rowmem['username'])
A few other notes:
You use the $SERVER['PHP_SELF'] variable, which is not safe. Use $SERVER['SCRIPT_NAME'] instead.
You use GLOBALS, which is considered bad practice. You can surely do without.
Your site might be vulnerable to injections and xss attacks. Maybe checkout (either read through it or use it) a prerolled authentication class (like mine, which you can find from this thread here on the forum - complete with examples and documentation)
And two final notes:
Please do use [ php] [ /php] tags around your code.
Please organize your code properly. See zend coding standards for a good guideline.
hth
Bjom