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.

2
  • 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? Commented May 19, 2014 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? Commented May 19, 2014 at 17:44

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

8 Comments

Its not displaying any
try make this in top of page ini_set('display_errors',1); or in your php.ini locate and do this display_errors = on
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.
added, still not displaying any, it used to display errors but then i found what was wrong and fixed them.
as i said check the other file where you defining session['level'] and check if you have session_start().
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.