[Solved] if-statement gives another result than expected


The if-statements you use are quite straightforward, the only possibility is that $_SESSION["Member_type"] always is the value "S". This means that the ‘problem’ is something else.

You can easily verify this yourself. Right before you do the if-statement, you place print_r($_SESSION). If you do that, you’ll see the values in the session array. It could be lowercased, or maybe simple set wrong.

This should always be your first test (to check the actual value, not what you think it is).


And while we’re at it, let’s add a bit of a code review. For what you’ve made, is another method which is more common to implement, the switch():

switch( strtoupper($_SESSION["Member_type"]) ){
    case 'S':
        include ('global/i-super_nav.php');
    break;
    case 'A':
        include ('global/i-admin_nav.php');
    break;
    case 'U':
        include ('global/i-member_nav.php');
    break;
    default:
        include ('global/i-nav.php');
    break;
}

I’ve added the strtoupper(). This way, if your value is S or s, it’ll work. Using string like that isn’t optimal, thats why we often use numbers, but this way you made it a bit more stupidproof 🙂

0

solved if-statement gives another result than expected