Jump to content

Login issue


dapcigar

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.