Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我需要一个带有不同变量的php双if语句_Php_If Statement_Pdo - Fatal编程技术网

我需要一个带有不同变量的php双if语句

我需要一个带有不同变量的php双if语句,php,if-statement,pdo,Php,If Statement,Pdo,到目前为止,我已经试过了: $query = "SELECT * FROM users WHERE id = :id"; $stmt = $connectionPDO->prepare($query); $stmt->bindParam(':id', $id); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $type = $row['rights']; if(check_login_status()

到目前为止,我已经试过了:

$query = "SELECT * FROM users WHERE id = :id";
$stmt = $connectionPDO->prepare($query);
$stmt->bindParam(':id', $id);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$type = $row['rights'];

if(check_login_status() == false)
{
   header("Location:error.php");
   exit;
}

如果特定用户的“权限”列中的条目为“用户”,并且没有人登录,则必须重定向到error.php。到目前为止,这还不起作用。如果我使用用户帐户登录,它仍然显示页面。希望我足够具体。

您的语法错误:

header("Location:error.php");

header()
函数中需要一条额外的信息,还需要添加一个
出口
头()之后。
否则执行将在此代码片段内继续

$row = $stmt->fetch(PDO::FETCH_ASSOC);
$type = $row['rights'];

if(check_login_status() == false && $type == "user")
{
    header("Location: error.php");
    exit;
}
当然,
if
语句的正确执行取决于您没有指定的内容,例如检查登录状态()
实际返回
false
,并且您是否检查了
$type
实际上是
“user”

尝试以下测试:

$row = $stmt->fetch(PDO::FETCH_ASSOC);
$type = $row['rights'];

// just testing
$type = "user";

if(check_login_status() == false && $type == "user")
{
    header("Location: error.php");
    exit;
}

的确是这样。我改了,但还是不起作用,起作用了。解决方案是一个单独的if语句:if($type!=“admin”){header('Location:error.php')exit;这样如果我没有登录,$type就不是“admin”。因此它会重定向。谢谢你的回答。顺便问一下,我如何关闭一个问题?谢谢你的回答。但问题实际上在于双if语句。我将它改为单if语句(只有check_login_status部分)它工作得很好。您已经检查了
$type
的实际值,字符串“user”是从具有特定ID的数据库条目中获取的。因此,如果“rights”列中的条目是“user”然后它将该值赋给变量$type。但是如果数据库值中的数据实际上是
“user”
“user”
或不完全是4个字符长的东西(=to
user
如果
语法没有问题,那么现在你必须检查它正在处理的数据!!!!