Page 1 of 1

Code Help PLEASE

Posted: Sun Mar 14, 2010 5:46 pm
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

Re: Code Help PLEASE

Posted: Sun Mar 14, 2010 6:08 pm
by requinix
You went wrong by not telling us anything about the problem(s) you're having.

Re: Code Help PLEASE

Posted: Sun Mar 14, 2010 6:21 pm
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

Re: Code Help PLEASE

Posted: Sun Mar 14, 2010 6:32 pm
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.

Re: Code Help PLEASE

Posted: Mon Mar 15, 2010 12:44 am
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';
}
?>

Re: Code Help PLEASE

Posted: Mon Mar 15, 2010 7:28 pm
by Patsman77
Excellent, that works perfect. Thanks for the help....

Re: Code Help PLEASE

Posted: Mon Mar 15, 2010 8:04 pm
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