Jump to content

[SOLVED] Login problem


rainemaida

Recommended Posts

Currently I have a login script that takes the user to a page after they have logged in. However, I would like to modify it so that if someone with status = 's' in the user table gets taken to one page and if you're not status 's' then u get taken to another.

 

if (isset($_POST['submitted']))
{
require_once ('db_connect.php');

$errors = array();

// checks for username

if (empty($_POST['userID']))
{
  $errors[] = 'You forgot to enter your username.';
}
else
{
	$u = $_POST['userID'];
}

//checks for password

if (empty($_POST['password']))
   {
	$error[] = 'You forgot to enter your password.';
   }
else
   {
	 $p = $_POST['password'];
   }

if (empty($errors))
{
	$query = "SELECT userID, password FROM user WHERE userID='$u' AND password='$p'";
	$result = @mysql_query ($query);
	$row = mysql_fetch_array ($result, MYSQL_NUM);

if ($row)
   {
   
	setcookie('login', $row[0], time()+2400, '/', '', 0);
	session_name('login_id');
    session_start();
  
    $_SESSION['userID'] = $row[0];
    $_SESSION['password'] = $row[1];

	header("Location: coursedocumentsstaff.php");
        
	exit();

   }

else
   {
	$errors[] = 'An error occurred while the system was processing this login request.';
		   }

}

mysql_close();

   }

 

status is a row in the user table but i didn't add it in the select statement to save any confusion for someone who is going to help out.

 

Cheers,

Steve

Link to comment
https://forums.phpfreaks.com/topic/45271-solved-login-problem/
Share on other sites

I added it like this

// checks for username

if (empty($_POST['userID']))
{
  $errors[] = 'You forgot to enter your username.';
}
else
{
	$u = $_POST['userID'];
}

//checks for password

if (empty($_POST['password']))
   {
	$error[] = 'You forgot to enter your password.';
   }
else
   {
	 $p = $_POST['password'];
   }

if (empty($errors))
{
	$query = "SELECT userID, password, status FROM user WHERE userID='$u' AND password='$p'";
	$result = @mysql_query ($query);
	$row = mysql_fetch_array ($result, MYSQL_NUM);

if ($row)
   {
   
	setcookie('login', $row[0], time()+2400, '/', '', 0);
	session_name('login_id');
    session_start();
  
    $_SESSION['userID'] = $row[0];
    $_SESSION['password'] = $row[1];


	 if ($row['status'] == 's') {
	header('Location: coursedocumentsstaff.php');
	} 

	else {
	header('Location: coursedocumentsstudent.php');
	}
        
	exit();

   }

else
   {
	$errors[] = 'An error occurred while the system was processing this login request.';
		   }

}

 

however when the person with status "s" logs in it still goes to coursedocumentsstudent.php and not the staff one.

 

Any ideas?

Cheers,

Steve

Link to comment
https://forums.phpfreaks.com/topic/45271-solved-login-problem/#findComment-219823
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.