igor221189 Posted April 20, 2011 Share Posted April 20, 2011 Hello, I would like to be able to redirect a user to a different page based on their login name. At the moment, the code below redirects all users to the same page (role.php) no matter what their login is. I have two users: student and tutor. Both of these users are redirected to role.php. However, I would like to redirect student user to role.php and tutor user to record.php. I've tried doing a couple of switch statements (shown as comments) like so: if login is student, then redirect to role.php and if login is tutor, then redirect to record.php. But they didn't work. Table structure for members table from where login credentials are checked is as follows: member_id: 1 or 2 login: student, tutor passwd: separate password for each user – encrypted with md5. Any help would be greatly appreciated. Thanks. //Create query $qry="SELECT * FROM members WHERE login='$login' AND passwd='".md5($_POST['password'])."'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) == 1) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['member_id']; session_write_close(); header("location: role.php"); // $login="student"; // $login="tutor"; // switch ($login) // { // case "student": // header("location: role.php"); // break; //case "tutor": //header("location: record.php"); //break; // } exit(); }else { //Login failed header("location: login-failed.php"); exit(); } }else { die("Query failed"); } Quote Link to comment Share on other sites More sharing options...
kney Posted April 20, 2011 Share Posted April 20, 2011 Doesn't it work better like this? $login="student"; $login="tutor"; if($login == "student"){ header("location: role.php"); }else{ header("location: record.php"); } Dunno for sure, it's been a lot time since i've done some php 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.