Instead of using session_register and session_is_register it is recommended to use the $_SESSION array directly as session_register functions family will be removed in the future.
so instead of
SESSION_REGISTER("username");
you'll have
$_SESSION['username'] = $username;
and instead of
session_is_registered('username')
you'll have
isset($_SESSION['username'])
Also on logout you should clear the username like this
unset($_SESSION['username']);
And a security issue I saw with your code, you should escape the variables passed to mysql that are received directly from the user's browser to avoid sql injection.
the code
$sql = "SELECT * FROM $table WHERE username='$username' and password='$password' and level='student'";
should be
$sql = "SELECT * FROM $table WHERE username='".mysql_real_escape_string($username)."' and password='".mysql_real_escape_string($password)."' and level='student'";
to avoid getting funny code in $_POST['username'] and $_POST['password'] transmitted to mysql as sql commands.