Martney Acha Martney Acha - 3 months ago 17
PHP Question

PHP ifelse display white screen of death

My code doesnt work properly and it does now shows any error or any clue, what am I missing here ? any hints ? TIA

<?php if(isset($_SESSION['user_session_organizer']))
{ ?>
<li><a href="triplist.php" class="smoothScroll">VIEW TRIPS</a></li>
<?php } ?>
<?php
elseif(isset($_SESSION['user_session']))
{
?>
<li><a href="triplist.php" class="smoothScroll">VIEW TRIPS</a></li>
<?php }else{ ?>
<li><a data-toggle="modal" href="#organizer" class="smoothScroll">ORGANIZE TRIPS</a></li>
<?php } ?>

Answer

One unnecessary <?php and else if is in wrong way, do like below:-

<?php if(isset($_SESSION['user_session_organizer'])){ ?>
    <li><a href="triplist.php" class="smoothScroll">VIEW TRIPS</a></li>
<?php } elseif(isset($_SESSION['user_session'])){?>
    <li><a href="triplist.php" class="smoothScroll">VIEW TRIPS</a></li>
<?php }else{ ?>
    <li><a data-toggle="modal" href="#organizer" class="smoothScroll">ORGANIZE TRIPS</a></li>
<?php } ?>

Note:-

Always add

error_reporting(E_ALL);ini_set('display_errors',1);

on top of your each php page to prevent yourself from a situation like:-"White Screen Of Death"

(It will on the error reporting setting for all type of errors and every error will displayed on the page if any occur).

Thanks

Comments