PHP syntax troubles
1 min read

PHP syntax troubles

For PHP syntax, I ran into an issue when trying to create an if else statement. Instead of just one portion of the code being run, both parts would be run if the first check was true. It was almost as though the "else" was being ignored completely. The issue turned out to be that my bracket wasn't spaced out correctly. The closing bracket must be have a space between it and the opening php tag.

<?php if (Auth::check()) {?>
	<div class="col-md-4 col-md-offset-4" style="text-align: center">Congratulations! You are logged in!</div>
    <?php } else { ?>

Here, it is spaced out correctly. My incorrect code was like so:
<?php} else {?>

Always remember to check spacing.