Is the UserID Session value being retrieved?
Try adding the following at line 1 of your page:
<?php if(!session_id()) session_start(); ?>
if you still having problems, add an echo of the UserID session variable to the page to ensure that it has a value:
<?php echo("UserID = ".isset($_SESSION['UserID'])?$_SESSION['UserID']:"nothing"); ?>
this will at least tell us if the userID session variable is the problem or not.