Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.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-Mysql的条件值并不总是相同的_Php_Mysql_If Statement - Fatal编程技术网

PHP-Mysql的条件值并不总是相同的

PHP-Mysql的条件值并不总是相同的,php,mysql,if-statement,Php,Mysql,If Statement,我有一段代码,它进行一个简单的查询,然后根据结果执行各种条件 变量$\u SESSION['nombre']不可能是错误的,因为分配值的页面之前已通过数据库进行检查 变量$\u POST['evaluado']也不会错,因为它是直接从数据库的已验证列表中部署的 问题是,一些用户(并非所有用户)一直在收到当条件mysqli_num_rows($result)>0为非真时显示的消息 我无法重现这个错误,我用用户名和密码运行了这段代码,这些用户名和密码可能会导致这个错误,但它对我来说完全正常,我无法重

我有一段代码,它进行一个简单的查询,然后根据结果执行各种条件

变量
$\u SESSION['nombre']不可能是错误的,因为分配值的页面之前已通过数据库进行检查

变量
$\u POST['evaluado']
也不会错,因为它是直接从数据库的已验证列表中部署的

问题是,一些用户(并非所有用户)一直在收到当条件
mysqli_num_rows($result)>0
为非真时显示的消息

我无法重现这个错误,我用用户名和密码运行了这段代码,这些用户名和密码可能会导致这个错误,但它对我来说完全正常,我无法重现这个错误,但我确实得到了显示给用户的错误截图

你在我的代码中看到什么可能导致有时条件是真的,有时不是真的

<?php
session_start();
header('Content-Type: text/html; charset=UTF-8');

$evaluador=$_SESSION['nombre'];
$evaluado=$_POST['evaluado'];

// Create connection
$conn = mysqli_connect("localhost", "sbp_admin", "sbp2014", "sbp_encuesta90");
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT Evaluador, Evaluado,Realizado FROM Beta WHERE Evaluador='$evaluador' AND Evaluado='$evaluado'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        if ($evaluado==$row['Evaluado']) {
            # code...
             if($row['Realizado'] == 0){
        $_SESSION['nombre']=$evaluador;
        $_SESSION['evaluado']=$evaluado;
        //echo $evaluado;
            header('Location: evaluacion.php');
    }
    else
    {
    echo "<!DOCTYPE html>";
    echo '<head><meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <link rel="stylesheet" href="style.css">
<script type="text/javascript">
 $(function() {
        /* For zebra striping */
        $("table tr:nth-child(odd)").addClass("odd-row");
        /* For cell text alignment */
        $("table td:first-child, table th:first-child").addClass("first");
        /* For removing the last border */
        $("table td:last-child, table th:last-child").addClass("last");
        $("table:last-child").addClass("last");
});
</script>
</head>
<body>
    <div style="width:1000; height:92px;margin: 0 auto;display: inline-block;"><div style="width:382; height:92px; display: inline-block;float: left;"><img src="logo.gif"></div><div style="width:328; height:41px; margin-top: 30px; display: inline-block;float: right;"><img src="logo.png"></div></div>
    <div><h1 style="float:left;">Evaluacion de Liderazgo 90&deg;</h1>
        <br><br>
        <br><br>
        <br><br><br><br><br><br>
        <p>Ya has evaluado a esta persona, <a href="index.html">regresa</a> a la p&aacute;gina principal de nuestra encuesta de liderazgo</p>
<br><br></body>';
        }
    }
        else{
        echo "<!DOCTYPE html>";
       echo '<head><meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <link rel="stylesheet" href="style.css">
<script type="text/javascript">
 $(function() {
        /* For zebra striping */
        $("table tr:nth-child(odd)").addClass("odd-row");
        /* For cell text alignment */
        $("table td:first-child, table th:first-child").addClass("first");
        /* For removing the last border */
        $("table td:last-child, table th:last-child").addClass("last");
        $("table:last-child").addClass("last");
});
</script>
</head>
<body>
    <div style="width:1000; height:92px;margin: 0 auto;display: inline-block;"><div style="width:382; height:92px; display: inline-block;float: left;"><img src="logo.gif"></div><div style="width:328; height:41px; margin-top: 30px; display: inline-block;float: right;"><img src="logo.png"></div></div>
    <div><h1 style="float:left;">Evaluacion de Liderazgo 90&deg;</h1>
        <br><br>
        <br><br>
        <br><br><br><br><br><br>
        <p>No puedes evaluar a esta persona, <a href="index.html">regresa</a> a la p&aacute;gina principal de nuestra encuesta de liderazgo</p>
<br><br></body>';
        }
} 
}
else
{
echo "<!DOCTYPE html>";
echo '<head><meta http-equiv="Content-Type" content="text/html; charset=euc-jp">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <link rel="stylesheet" href="style.css">
<script type="text/javascript">
 $(function() {
        /* For zebra striping */
        $("table tr:nth-child(odd)").addClass("odd-row");
        /* For cell text alignment */
        $("table td:first-child, table th:first-child").addClass("first");
        /* For removing the last border */
        $("table td:last-child, table th:last-child").addClass("last");
        $("table:last-child").addClass("last");
});
</script>
</head>
<body>
    <div style="width:1000; height:92px;margin: 0 auto;display: inline-block;"><div style="width:382; height:92px; display: inline-block;float: left;"><img src="logo.gif"></div><div style="width:328; height:41px; margin-top: 30px; display: inline-block;float: right;"><img src="logo.png"></div></div>
    <div><h1 style="float:left;">Evaluacion de Liderazgo 90&deg;</h1>
        <br><br>
        <br><br>
        <br><br><br><br><br><br>
        <p>Verifica tu correo ya que el que ingresaste no esta en nuestra base de datos, <a href="index.html">regresa</a> a la p&aacute;gina principal de nuestra encuesta de liderazgo</p>
<br><br></body>';
}
mysqli_close($conn);
?>

如果这不是真的,则表示查询返回0行

您是否完全确定每个可能的
Evaluador
Evaluado
对都至少有一行要返回

您还可以检查添加此条件的查询中是否存在错误:

...
$result = mysqli_query($conn, $sql);
if (!$result) {
   // Display error and store the pair of inputs for debugging
}
else if (mysqli_num_rows($result) > 0) {
...

错误日志(“查询失败:$sql”)
添加到
else
子句中。然后,当用户报告失败时,检查PHP日志中的消息,以便查看它正在运行的查询。客户端发送了一个POST变量,我在代码中没有看到任何验证。那么它在哪里以及如何根据数据库进行验证呢?嗨,POST值是从上一页的单选按钮列表中发送的。该列表直接从查询打印到数据库,该数据库检查与用户匹配的字段,因此,如果该列表存在,则是因为它在数据库中。我会添加上一页的代码,这样你可以看到我的意思,只要我到我的笔记本电脑。另一件让我感到困难的事情是,当我尝试使用用户数据编写代码时,我没有得到那个错误。我正在尝试上述错误日志诊断的解决方案,但用户尚未登录。您好,Alvaro,是的,这些值必须存在,因为在上一页中值以前使用过,它们存储在这个.php中使用。。。检查错误是我遇到的问题的一部分,因为当我测试它时,它不会显示任何问题,换句话说,我访问该站点,查询不会返回0,php执行顺利,用户是有问题的用户,但他不能亲自让我去检查他在做什么。代码对我来说似乎很好,我将继续添加
if(!$result){…}
以检查问题是否是查询执行不正确。