我在哪里添加if语句,根据用户的类型将用户重定向到不同的页面? [英] Where do I add an if statement that redirects the user to different pages depending on their type?

查看:109
本文介绍了我在哪里添加if语句,根据用户的类型将用户重定向到不同的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个if语句,其中user_type = 1被重定向到admin.html,user_type = 0被重定向到user.html。但我不知道在哪里或如何写它。我只能为普通用户使用的代码。



I want to add an if statement where user_type=1 gets redirected to admin.html and user_type=0 gets redirected to user.html. But I don't know where or how to write it. The code that I have only works for normal users.

<?php
	require_once ('../../connect.php');
	$user_email = $_POST['user_email'];
	$user_password = $_POST['user_password'];

	if ($user_email != NULL AND $user_password != NULL) 
	{
		$login = "SELECT * FROM tblusers where user_email = '$user_email' AND user_password = '$user_password' AND user_type=0";
		$result = mysqli_query($dbc, $login);

		if (mysqli_num_rows($result) >0)
		{
			setcookie('user_email', $user_email);
			setcookie('user_password', $user_password);

			echo ' window.location ="user.html<b></b>"; ';
		}

		else
		{
		echo ' alert("The email or password you have entered may be incorrect"); window.location ="login.html"; ';	
		}
	}

	else
	{
		echo ' alert("Please enter your email and password in the relative fields"); window.location ="login.html"; ';		
	}

	mysqli_close($dbc);
?>





我有什么试过:





What I have tried:

<?php
    require_once ('../../connect.php');
    $user_email = $_POST['user_email'];
    $user_password = $_POST['user_password'];

    if ($user_email != NULL AND $user_password != NULL) 
    {
        $login = "SELECT * FROM tblusers where user_email = '$user_email' AND user_password = '$user_password' AND user_type=0";
        $result = mysqli_query($dbc, $login);

        if (mysqli_num_rows($result) >0 ) 
        {
            setcookie('user_email', $user_email);
            setcookie('user_password', $user_password);

            echo ' window.location ="user.html"; ';
        }

        else
        {
        echo ' alert("The email or password you have entered may be incorrect"); window.location ="login.html"; ';  
        }
    }

    else ($user_email != NULL AND $user_password != NULL) 
    {
        $login = "SELECT * FROM tblusers where user_email = '$user_email' AND user_password = '$user_password' AND user_type=1";
        $result = mysqli_query($dbc, $login);

        if (mysqli_num_rows($result) >0 ) 
        {
            setcookie('user_email', $user_email);
            setcookie('user_password', $user_password);

            echo ' window.location ="admin.html"; ';
        }

        else
        {
        echo ' alert("The email or password you have entered may be incorrect"); window.location ="login.html"; ';  
        }
    }

    else
    {
        echo ' alert("Please enter your email and password in the relative fields"); window.location ="login.html"; ';      
    }

    mysqli_close($dbc);
?>

推荐答案

user_email =
user_email =


_POST [' user_email'];
_POST['user_email'];


user_password =
user_password =


这篇关于我在哪里添加if语句,根据用户的类型将用户重定向到不同的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆