【问题标题】:if statement always display true even the input is false即使输入为假,if 语句也始终显示为真
【发布时间】:2013-09-26 20:14:23
【问题描述】:
<?php

    include("connection2.php");     

    if(!empty($_POST['lrn'])  && !empty($_POST['password'])){

        $lrn = $_POST['lrn'];
        $pass = $_POST['password'];
        $check = "SELECT * from studentinf where LRN = '".$lrn."'";
        $qry = mysql_query($check);
        $num_rows = mysql_num_rows($qry); 
        $check2 = "SELECT * from studentinf where Password = '".$pass."'";
        $qry2 = mysql_query($check2);
        $num_rows2 = mysql_num_rows($qry2); 

        if($num_rows > 0){
            echo "<center>LRN is valid</center> ";
        }

        else 
            echo "<font color='#FF0000'><center>Your LRN is Invalid. <br>Please Contact your Web   Administrator for your LRN.</center></font>";


        if($num_rows2 != "")
        {
            echo "account already registered";            
        }

        else if ($num_rows2 == "")
        {
            echo "account not yet registered";
            $query = "UPDATE studentinf SET Password = '$pass' where LRN = '$lrn'";
            mysql_query($query);

            echo "Thank You for Registration.";
            echo '<br><a href="studentlogin.php">Click Here</a> to login your account.';
        }
    }
 ?>

【问题讨论】:

标签: php registration


【解决方案1】:

如果我猜对了您所说的 if 语句,请尝试替换:

if($num_rows2 != "")
{
  echo "account already registered";
}
else
if ($num_rows2 == "")
{
  // ...
}

与:

if ($num_rows2 > 0)
{
  echo "account already registered";
}
else
{
  // ...
}

$num_rows2 是数字;将其与数字而非字符串进行比较。

【讨论】:

    猜你喜欢
    • 2019-10-05
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    • 2021-01-07
    相关资源
    最近更新 更多