Accessing HTML content with Jquery and PHP

Accessing HTML content with Jquery and PHP

Hi, I'll try to keep this as simple as possible, and I apologise for my bad english

I have a register-page.php file which contains
<?php include "includes/functions/Register/Register.php"?>
<?php include "includes/header.php"?>
<?php include "includes/navbar.php"?>
<?php include "includes/registerContainer.php"?>
<?php include "includes/hidden.php"?>
<?php include "includes/footer.php"?>

Note that in the first line Register.php holds my functions.

The Display function inside the Register.php:

function errorDisplay($regErrors){
//Display Errors
foreach ($regErrors as $errrorMessage) {
?>
<script>
$("#errors").append('<div class="alert alert-danger" role="alert"><?php echo $errrorMessage; ?></div>');
if($(window).width()<=1024 && $(window).height()<=768){
$(".registerContainer").animate({marginBottom:"75vh"});
}
else{
$(".registerContainer").animate({marginBottom:"60"});
}
</script>
<?php
}
}

My Problem is When I place the Register.php under the footer.php ( at the bottom) everything works perfectly
except that I'm not able to use Sessions, but I can see the error messages on the screen.

however when I place Register.php on top, the functions work (I can register to the database) but I am not able to see the error messages on the screen, what could possibly cause this?
any help or advice?