-1

Why does my page turn blank when i insert this line of PHP code into my navigation bar? the navigation works correctly without the PHP code in it.

This is my code:

<section id="header">
        <div class="header container">
            <div class="nav-bar">
                <div class="banner-title">
                    <a href="#home"><h1><span>K</span>LJ <span>N</span>ieuwrode</h1></a>
                </div>
                <div class="nav-list">
                    <div class="hamburger"><div class="bar"></div></div>
                    <ul>
                        <li><a href="#home" data-after="Home">Home</a></li>
                        <li><a href="#nieuws" data-after="Nieuws">Nieuws</a></li>
                        <li><a href="#maandprogrammas" data-after="Maandprogrammas">Maandprogramma's</a></li>
                        <li><a href="index2-albums.php" data-after="Foto's">Foto's</a></li>
                        <li><a href="#verhuur" data-after="Verhuur">Verhuur</a></li>
                        <li><a href="#groepsleiding" data-after="Leiding">Leiding</a></li>
                        <li><a href="#contact" data-after="Contact">Contact</a></li>
                        <?php
                            if (isset($_SESSION["useruid"])) {
                                echo "<li><a href="../admin/admin.php" data-after="Admin">Log In</a></li>";
                            }
                            else {
                                echo "<li><a href="login.php" data-after="Login">Log In</a></li>";
                            }
                        ?>
                    </ul>
                </div>
            </div>
        </div>
    </section>
  • 1
    Quoting issues. You need to either use single quotes for outer or escape the inner double quotes. Also, for future reference, see how to get [PHP errors to display](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display), so that PHP can tell you what's going wrong instead of simply giving you a blank page. But remember that this should only be turned on in development, not in a live environment. – El_Vanja Mar 04 '21 at 10:43
  • You could also utilize the [alternative syntax](https://www.php.net/manual/en/control-structures.alternative-syntax.php) so that you can directly write HTML instead of having to echo it. – El_Vanja Mar 04 '21 at 10:44

1 Answers1

0

You are echoing a statement with double quotes and in this string you also use double " quotes for html attributes, which results in php error. You must add string in single ' quotes and it should be fine.

if (isset($_SESSION["useruid"])) {
    echo '<li><a href="../admin / admin . php" data-after="Admin">Log In</a></li>';
} else {
    echo '<li><a href="login . php" data-after="Login">Log In</a></li>';
}
GrandFelix
  • 512
  • 5
  • 9