Code Help PLEASE

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

Post Reply
Patsman77
Forum Newbie
Posts: 18
Joined: Thu Jun 04, 2009 10:09 am

Code Help PLEASE

Post by Patsman77 »

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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Code Help PLEASE

Post by requinix »

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

Re: Code Help PLEASE

Post by Patsman77 »

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

Re: Code Help PLEASE

Post by Trahb »

Code: Select all

if($_SESSION['user'] != "")
Right there you're telling it to only execute that code if user != ""

Code: Select all

elseif ($_SESSION['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

Re: Code Help PLEASE

Post by rahulzatakia »

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

Re: Code Help PLEASE

Post by Patsman77 »

Excellent, that works perfect. Thanks for the help....
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Code Help PLEASE

Post by mikosiko »

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 8O
Post Reply