1

Each user in the databased is assigned a level, their is a table for levels and each level has permissions eg "view-clients" at login the user's level is made into $_SESSION['level'] i need to make an if statement that will echo code if the user's level "view-clients" is "checked".

This is the code is have but it wont echo it even when it is checked.

<?php
$level = mysql_real_escape_string($_SESSION['level']);
include("include/config.php");
$con=mysql_connect($db_host,$db_uname,$db_pwd,$db_name);
mysql_select_db($db_name);
$query = "SELECT * FROM levels WHERE name='$level'";

            $result=mysql_query($query);
            while($rows = mysql_fetch_array($result)){
                $a1=$rows['0'];
                $a2=$rows['1'];
                $a3=$rows['2'];
                $a4=$rows['3'];
                $a5=$rows['4'];
                $a6=$rows['5'];
                $a7=$rows['6'];
                $a8=$rows['7'];


if ($a5=="checked") { 

echo "Clients"; 

     }

 }

?>

I have tried a few things such as not using a variable as the session. I am thankful for any help.

James
  • 41
  • 4
  • So `name` is unique in `levels`? Did you try `var_dump($row[5]);` inside the loop to see if you're getting anything at all? – kero May 19 '14 at 17:28
  • I guess this is where im going wrong, its not outputting anything. I have triple checked everything and it is spelled correctly? – James May 19 '14 at 17:44

1 Answers1

0

I guess you forgot to start session.

try that

  <?php
  session_start();
  $level = mysql_real_escape_string($_SESSION['level']);
  ....

your query will not find and result while $level is not defined.

also chanage this

 mysql_fetch_array

to

mysql_fetch_row

Look here the difference betwen fetch row and fetch array and fetch assoc

Community
  • 1
  • 1
echo_Me
  • 37,078
  • 5
  • 58
  • 78
  • Its not displaying any – James May 19 '14 at 17:48
  • try make this in top of page `ini_set('display_errors',1);` or in your php.ini locate and do this `display_errors = on` – echo_Me May 19 '14 at 17:48
  • if nothing happen , then you have to check if you are really submitting having value for `$_SESSION['level']` , if not , then check that you made session_start() also in the file you defining this variable. – echo_Me May 19 '14 at 17:50
  • added, still not displaying any, it used to display errors but then i found what was wrong and fixed them. – James May 19 '14 at 17:51
  • as i said check the other file where you defining session['level'] and check if you have session_start(). – echo_Me May 19 '14 at 17:52
  • yeah its defined in my login.php file, and it has session_start() in it. – James May 19 '14 at 18:01
  • last suggest , you sure that you checking for `$a5` ? – echo_Me May 19 '14 at 18:04
  • The code is in my sidebar.php (show extra nav menu if has permissions) and is included in the other pages, could this be affecting it? – James May 19 '14 at 18:04