0

hi all,
i am having a login page.so that if role==0 it moves to one page and if role==1 moves to another page,if role==2 it moves to some other page. In this i need to add another condition if status is active(1) so i had done that but i am not getting it.Wat i mean is if status is '1' then only it should move to those pages.so can any one.

Thanks in advance.

$sql = mysql_query("SELECT role FROM users WHERE username='$username' AND password='$password'");
                    if($info = @mysql_fetch_array($sql))
                    {
                        if($info['role']=='0')
                        {
                            @header('location: http://localhost/Project/Superadmin.php');
                        } 
                        else if($info['role']=='1')
                        {
                            @header('location: http://localhost/Project/Admin.php');
                        } 
                        else if($info['role']=='2')
                        {
                            @header('location: http://localhost/Project/User.php');
                        }

so how can i check status also like

SELECT status FROM users WHERE username='$username' AND password='$password'
5
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by somedude3488
0

hi all,
i am having a login page.so that if role==0 it moves to one page and if role==1 moves to another page,if role==2 it moves to some other page. In this i need to add another condition if status is active(1) so i had done that but i am not getting it.Wat i mean is if status is '1' then only it should move to those pages.so can any one.

Thanks in advance.

$sql = mysql_query("SELECT role FROM users WHERE username='$username' AND password='$password'");
                    if($info = @mysql_fetch_array($sql))
                    {
                        if($info['role']=='0')
                        {
                            @header('location: http://localhost/Project/Superadmin.php');
                        } 
                        else if($info['role']=='1')
                        {
                            @header('location: http://localhost/Project/Admin.php');
                        } 
                        else if($info['role']=='2')
                        {
                            @header('location: http://localhost/Project/User.php');
                        }

so how can i check status also like

SELECT status FROM users WHERE username='$username' AND password='$password'

write like this $sql = mysql_query("SELECT * FROM users WHERE username='$username' && password='$password' && status=1");

0

First of all, make sure that you add 'status' to your database in line with username and password and set the values for each. If that's done then you can try this code.

sql = mysql_query("SELECT role FROM users WHERE username='$username' AND password='$password'");
if($info = @mysql_fetch_array($sql)){
	if($info['status']=='1'){	
		if($info['role']=='0'){
			@header('location: http://localhost/Project/Superadmin.php');
		} else if($info['role']=='1'){
			@header('location: http://localhost/Project/Admin.php');
		} else if($info['role']=='2'){
			@header('location: http://localhost/Project/User.php');
		}
	} else {
		echo "You are restricted to access this site.";
	}
}

Edited by deleted1234: n/a

0

The @ is for error suppression. Its slow and shouldn't be used much.

$query = mysql_query("SELECT `status`,`role` FROM `users` WHERE `username` = '" . mysql_real_escape_string( $username ) . "' AND `password` = '" . mysql_real_escape_string( $password ) . "' LIMIT 1");
if ( mysql_num_rows( $query ) == 1 ) {
	list( $status,$role ) = mysql_fetch_row( $query );
	if ( $status == 1 ) {
		switch( $role ) {
			case 0:
				$page = 'Superadmin.php';
			break;
			case 1:
				$page = 'Admin.php';
			break;
			case 2:
				$page = 'User.php';
			break;
		}
		header("Location: http://localhost/Project/{$page}");
		exit();
	}
	else {
		echo 'You don\'t not have permission';
	}
}
else {
	echo 'User not found';
}

That is how I would do it.

Edited by somedude3488: n/a

0

WOW, is it better on the server to use the switch() and the case: than else if statements?

also, can u only use case with numbers like
case 0:
case 55:
or can u use it with liike words and stuff?
like case freakin:
case word here:

Edited by SKANK!!!!!: n/a

0

To my knowledge they are pretty much equal. In some cases if-else statements can be faster.

You can use words.

$var = 'someword';
switch( $var ) {
  case "someword":
    echo 'var = someword';
  break;
}

Edited by somedude3488: n/a

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.