Value not being saved in session

I have a login page setup and I want to store the value of user_level in the session so that on certain pages I can do a if user_level == X echo these options

this page below is my login_check.php. This works with my login page to login. I have the value to store the user_level in the session but it’s not working
[php]

<?php session_start(); include('connection.php'); $login = mysql_query("SELECT * FROM $table2 WHERE (username = '" . mysql_real_escape_string($_POST['username']) . "') and (password = '" . mysql_real_escape_string(md5($_POST['password'])) . "')"); if (mysql_num_rows($login) == 1) { $_SESSION['username'] = $_POST['username']; $_SESSION['user_level'] = $_POST['user_level']; header('Location: .././site/index.php'); } else { header('Location: .././index.php'); } ?>

[/php]

Here is my login page.

[php]

Login

Login Page


Username :
Password :
Register
[/php]

Example of my top.php

[php]

Currently logged in as <?php echo $_SESSION['username']; ?> Logout
Userlevel <?php echo $_SESSION['user_level']; ?>

[/php]

The username shows but the user_level doesn’t

Thoughts?

The form doesn’t post a value for ‘user_level’

In addition, you also seem to be missing the session_start() statement needed before accessing/modifying any $_SESSION data. Although you could have very well left that line out when you copy pasted your code here.

Sponsor our Newsletter | Privacy Policy | Terms of Service