0

i having problem and stucked with retrieving like lastnametname. and i am stucked with how do i check if admin=1 will redirect to admin.php if admin=0 will redirect to welcome.php instead.

this is the part of my login process script

$q = "SELECT * FROM members2 WHERE (email='$e' AND password='$p')";	
		$q2 = "SELECT admin FROM members2 WHERE (admin='1')";	
		

	$r = mysqli_query ($dbc, $q);

	
	
	if (mysqli_num_rows($r) == 1)   { // A match was made.		
		// Get the data:
		//header('Location: welcome.php');
	
		
		
		$welcomepage = "welcome.php";
		
		echo '<script language="javascript" type="text/javascript">window.location.href="'.$welcomepage.'";</script>';
		
		$row = mysqli_fetch_array ($r, MYSQLI_NUM); 
	         $lastname = $row['lastname'];
		$_SESSION['lastname'] = $lastname;


			
		$_SESSION['email'] = $_POST['email'];
	
	
	}
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by mikulucky
0

Firstly your queries don't make sense, because your selecting an admin where there is admin, surely you want to test to see if the user who has just logged in is admin or not. Secondly you need to get the details of the user currently logged in, which you are doing, then admin should be in the information from that result.

Then you would want to use an IF statement to see if admin is '1', if that is the case then use a redirect to the admin page. ELSE redirect to the welcome page


This is the basic idea, not the actual code.

$queryGetUser = "SELECT * FROM usertable WHERE email = '$email' AND password = '$password' " ;

$queryGetUser = mysql_query ( $queryGetUser ) ;

$queryGetUser = mysql_fetch_assoc($queryGetUser)

if ( $userInformation )
{
    if ( $userInformation['admin'] )
    {
        // redirect to admin page;
    }

    else
    {
        // redirect to welcome page;
    }

}

else
{
    // redirect to login page;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.