azeem123456 Posted March 11, 2010 Share Posted March 11, 2010 i am setting session for a user when a user login it redirect to staff.php file in the start of staff.php there msg should display welcomes to the staff area and my user namee i mean if i login with name azeem then it shud say welcome to staff area ,azeem problem is this when i hit login button it takes me to staff.php area with this warning or error msg kindly help methis is the msg i got Staff Menu Welcome to staff Area., Notice: Undefined index: username in C:\wamp\www\az\staff.php on line 14 this is my few lines of code where i set my session $username = trim(mysql_prep($_POST['username'])); $password = trim(mysql_prep($_POST['password'])); $hashed_password = sha1($password); if ( empty($errors) ) { $query = "SELECT id,username "; $query .= "FROM users "; $query .= "WHERE username = '{$usrname}' "; $query .= "AND hashed_password ='{$hashed_password}' "; $query .= "LIMIT 1"; $result_set=mysql_query($query); confirm_query($result_set); if(mysql_num_rows($result_set)==1){ $found_user=mysql_fetch_array($result_set); $_SESSION['user_id']= $found_user['id']; $_SESSION['username'] =$found_user['username']; redirect("staff.php"); } else { $message="username/Password combination incorrect.<br/> check may be caplocks is on and try again."; } and in staff.php i m calling it this session is like this <td width="891" align="left" bgcolor="#FFFFFF" id="pages"> <h2>Staff Menu</h2> <p> Welcome to staff Area.,<?php echo $_SESSION['username'];?></p> Quote Link to comment Share on other sites More sharing options...
schilly Posted March 11, 2010 Share Posted March 11, 2010 anywhere you use sessions, you need to have session_start(); at the top of your file. If you don't call session_start(), none of your session calls will work. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.