PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Patsman77
Forum Newbie
Posts: 18 Joined: Thu Jun 04, 2009 10:09 am
Post
by Patsman77 » Sun Mar 14, 2010 5:46 pm
Hello All,
I am having a little difficulty with some code I am working on and wondering if anyone can tell me where I am going wrong.
Code: Select all
<?php
if($_SESSION['user'] != "")
{
$user=$_SESSION['user'];
$sql="select * from ".$football->prefix."users where user = '".$user."'";
$rs=$football->dbQuery($sql);
$row = mysql_fetch_object($rs);
if ($row->name == $football->admin_username)
{
include 'adminmenu.php';
}
elseif (($row->name != $football->admin_username) and ($row->name != ""))
{
include 'menu.php';
}
elseif ($_SESSION['user'] == "")
{
include 'menu2.php';
}
}
?>
Basically, I have 3 seperate menu's to pull -
1.) Admin menu
2.) logged in menu
3.) Non-logged in menu.
Any help would be appreciated.
Thanks,
Patsman77
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Mar 14, 2010 6:08 pm
You went wrong by not telling us anything about the problem(s) you're having.
Patsman77
Forum Newbie
Posts: 18 Joined: Thu Jun 04, 2009 10:09 am
Post
by Patsman77 » Sun Mar 14, 2010 6:21 pm
Sorry,
The last part of the code isnt working. If a user is not logged in, there is no menu. If I log in as Admin - i get correct menu, and if I log in with a user I get correct menu.
I have confirmed that all 3 menu's are loaded on server.
Thanks
Trahb
Forum Commoner
Posts: 36 Joined: Sat Jan 30, 2010 9:09 pm
Post
by Trahb » Sun Mar 14, 2010 6:32 pm
Right there you're telling it to only execute that code if user != ""
Here you're telling it to include the menu file if it DOES = ""
They're contradicting. just use "else" instead of "elseif", that way, if neither of the other things apply it'll fall back on just including the regular menu.
rahulzatakia
Forum Commoner
Posts: 59 Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad
Post
by rahulzatakia » Mon Mar 15, 2010 12:44 am
I have make the changes in code for you.
<?php
if($_SESSION['user'] != "")
{
$user=$_SESSION['user'];
$sql="select * from ".$football->prefix."users where user = '".$user."'";
$rs=$football->dbQuery($sql);
$row = mysql_fetch_object($rs);
if ($row->name == $football->admin_username)
{
include 'adminmenu.php';
}
elseif (($row->name != $football->admin_username) and ($row->name != ""))
{
include 'menu.php';
}
}
elseif ($_SESSION['user'] == "")
{
include 'menu2.php';
}
?>
Patsman77
Forum Newbie
Posts: 18 Joined: Thu Jun 04, 2009 10:09 am
Post
by Patsman77 » Mon Mar 15, 2010 7:28 pm
Excellent, that works perfect. Thanks for the help....
mikosiko
Forum Regular
Posts: 757 Joined: Wed Jan 13, 2010 7:22 pm
Post
by mikosiko » Mon Mar 15, 2010 8:04 pm
rahulzatakia wrote: I have make the changes in code for you.
Code: Select all
<?php
[color=#FF0000]if($_SESSION['user'] != "")[/color]
{
<<< OLD CODE WAS HERE >>
}
[color=#FF0000]elseif ($_SESSION['user'] == "")[/color]
{
include 'menu2.php';
}
?>
Granted... work... but what a curious way to implement it