Jump to content

Recommended Posts

i want my login page to redirect to different pages depending on the id provided.. the code below..

 

include('mysql_connect.php');

    
    
    $sql = mysql_query("SELECT * FROM users
        WHERE username='$username' AND
        password='$password'
        LIMIT 1");
    if(mysql_num_rows($sql) == 1){
        $row = mysql_fetch_array($sql);
        session_start();
        $_SESSION['username'] = $row['username'];
        $_SESSION['firstname'] = $row['firstname'];
        $_SESSION['lastname'] = $row['lastname'];
        $_SESSION['department'] = $row['department'];
        $_SESSION['logged'] = TRUE;
        
        
         if ($position == "Admin")
  {
  header("Location: admin/Admin_dash.php");
  exit;
  }
 
    if ($position == "HOD" && $department == "Account")
  {
  header("Location: hod/hod_dash.php");
  exit;
  }

  else
  {
 
 
  header("Location: staff/staff_dash.php");
  exit;
  }

 

 

Please, how can i retrieve the position from the DB and use it to run an IF statement?

Link to comment
https://forums.phpfreaks.com/topic/288370-login-issue/
Share on other sites

As I was reading your code the first question that came to mind was "where is $position coming from"  But you question at the end resolved that one and created a new one.  What do you mean "retrieve the position"?  Is position a field in your table - just add it to the query.  If not, where does position come from?

Link to comment
https://forums.phpfreaks.com/topic/288370-login-issue/#findComment-1478878
Share on other sites

I'm not that good at PHP, but I'll try to help.

 

It sounds like you have different types of members, admins and just members. I would create a row in the database and call it 'Level'. When a normal member signs up, give them a Level 0. And then all Admins would have a level 1 which could just be manually put in the database. So then you have two different level types of members. On your redirect have it check if the member that is signed in is a Level 1 or Level 0, and then redirect accordingly.

 

Like I said, I don't know that much about PHP, but that is what I would do. Hope that helps.

 

Also, I think posting the login form and the full login script would help lots.

Edited by JustinStone
Link to comment
https://forums.phpfreaks.com/topic/288370-login-issue/#findComment-1478959
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.