[SOLVED] Using || operator correctly

I’m trying to use the " || " operator in the below script but I don’t know why it’s not working can some one help me to figure this out please.

  include_once ('connect.php');
    include_once('sessioncheck.php');
    
    $id = $_SESSION["iD"];
    
    $selSql = "SELECT name FROM users WHERE uId=:id";
    $runSql = $dbConnect -> prepare($selSql);
    $runSql -> bindParam(':id', $id);
    $runSql -> execute();
    
    $row = $runSql -> fetch(PDO::FETCH_ASSOC);
    ?>
    <html>
    <head>
        <title>Super11 Player Management System</title>
    </head>
    <body style="background-image: url('images/mainbg.png'); background-repeat: no-repeat; background-position: 100% -12%">
    <div style="position: absolute; left: 1px; top: 14px; height: 223px; width: 230px;">
    <?php if($_SESSION["uType"] == "Admin" || $_SESSION["uType"] == "admin") {?>
    <script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]",awmMenuName="menuadmin",awmBN="868";awmAltUrl="";</script><script charset="UTF-8" src="menu/menuadmin.js" type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>
    <?php } else if($_SESSION["uType"] == "Manager" || $_SESSION["uType"] == "manager") { ?>
        <script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]",awmMenuName="menuman",awmBN="868";awmAltUrl="";</script><script charset="UTF-8" src="menu/menuman.js" type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>
        <?php } else if($_SESSION["uType"] == "User"  || $_SESSION["uType"] == "user") { ?>
        <script type="text/javascript">var MenuLinkedBy="AllWebMenus [4]",awmMenuName="menuuser",awmBN="868";awmAltUrl="";</script><script charset="UTF-8" src="menu/menuuser.js" type="text/javascript"></script><script type="text/javascript">awmBuildMenu();</script>
    <?php } ?>
    </div>

You are? Where? Sorry, I’ve looked a few times but I’m not seeing it.

Sorry, I copied the wrong code it was my old one. I corrected it now.

Try adding this block of PHP code in to see what you see.

<body style="background-image: url('images/mainbg.png'); background-repeat: no-repeat; background-position: 100% -12%">
<?php
/* for debugging only */
if ($_SESSION["uType"]) {
	echo $_SESSION["uType"] . "<br>";
} else {
	echo "No SESSION uType" . "<br>";
}
?>
    <div style="position: absolute; left: 1px; top: 14px; height: 223px; width: 230px;">

Where have you called session_start? What does $session[uType] contain? [fphp]Var_dump[/fphp] it.

EDIT: or use the code block provided :stuck_out_tongue: simultaneous posting.

session_start() is in side my connect.php which is included in almost all the pages where I need session and database.

When I use it with out the “||” operator it works with out any issue also switches the menus as expected but when I add the “||” operator it just don’t work when the session is set to “admin”.

It could be “precedence”. I never bother trying to remember and always use more parens than needed to force the issue. eg.
( ($_SESSION["uType"] == "Admin") || ($_SESSION["uType"] == "admin") )

1 Like

Maybe just forcing the $_SESSION[‘uType’] to lowercase could be a work-around?

session_start();

$_SESSION['uType'] = 'Admin';

if ( strtolower($_SESSION['uType']) == 'admin') {
	echo $_SESSION['uType'] . "<br>\n";
}

$_SESSION['uType'] = 'ADMIN';

if ( strtolower($_SESSION['uType']) == 'admin') {
	echo $_SESSION['uType'] . "<br>\n";
}

This was what I was missing it’s working now thank you.

== has higher precedence than ||, so it should have worked without the extra partenthesis… I suspect a different problem was simply skirted around here, but whatever :stuck_out_tongue:

1 Like

Any way you have helped me a lot lion.