If the problem is not session-related, then here are some possibilities:
1) Use $SERVER["PHP_SELF"] instead of $PHP_SELF. The latter is deprecated, anyway.
2) Use the $POST and $GET arrays ... eg use $POST["usernick"] (or $_GET["usernick"]) rather than $usernick
3) Don't use variables inline strings because they are error-prone, so ...
$name = "Fred";
echo "Hello ".$name.", how are you!";
//... is better than ...
$name = "Fred";
echo "Hello $name, how are you!";
// In fact, I think this may be your problem. You've got ...
$result = mysql_query("SELECT * FROM users WHERE userID='$_SESSION[logged_in]'") or die ("Invalid query");
// Try ...
$result = mysql_query("SELECT * FROM users WHERE userID='".$_SESSION["logged_in"]."'") or die ("Invalid query");