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'

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");

Member Avatar for deleted1234

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.";
	}
}

what the heck is the @ doing in the code? i never use that

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.

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:

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;
}

what "cases" are they faster in?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.