This question already has answers here:
The 3 different equals
(5个答案)
两年前关闭。
$check1 = mysqli_query($conn, "select * from Sailors where Name='$habboname'");
$check2 = mysqli_query($conn, "select * from Sailors where Position='$position'");
$num_rows = mysqli_num_rows($check1);
$num_rows2 = mysqli_num_rows($check2);
if ($num_rows > 0)  {
    echo "This user (<b>" . $habboname . "</b>) is already in our database.";
    exit();
} else {
    if ($num_row2 = 0){
    $sql =  "INSERT INTO Sailors (ID, Name, Joined, Rank, Billet, Position, Status, Promoter, Reason, Promo_Date)
    VALUES ('', '$habboname', '$date', '$rank', '$billet', '$position', 'Active', '$promoter', '$reason', '$date')";

    if ($conn->query($sql) === TRUE) {
        header("Location: useradded.php");
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
} else {
        echo $num_row2;
    }

即使变量为0,它也将始终回显。我真的很困惑。
如果你知道问题是什么,请告诉我。
谢谢:)

最佳答案

您正在检查作业:

if ($num_row2 = 0){

虽然您应该检查是否相等:
if ($num_row2 == 0){

关于php - 我的变量为零,但IF无法识别? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46009054/

10-12 00:48