sand12
October 18, 2014, 8:18am
1
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.
sand12
October 18, 2014, 8:44am
3
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 simultaneous posting.
sand12
October 18, 2014, 9:08am
6
session_start() is in side my connect.php which is included in almost all the pages where I need session and database.
sand12
October 18, 2014, 9:10am
7
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
Pepster
October 18, 2014, 10:54am
9
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";
}
sand12
October 18, 2014, 12:49pm
10
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
1 Like
sand12
October 18, 2014, 1:47pm
12
Any way you have helped me a lot lion.