接收到错误消息,尽管正在发送数据

时间:2019-05-29 04:46:19

标签: php

我最近实现了许多if语句,用于检查是否已输入需求数据,如果没有输入,则会收到错误消息something is wrong with...。但是在实现它们之后,无论数据是否实际上已经发送到数据库(正在发送的数据都是正确的),我现在都可以收到该错误消息,而且我一生都无法弄清楚原因。

$query = "insert into $sql_table (Eoi, Job_reference_number, First_Name, Last_Name, Street_Address, Suburb, State, Postcode, Email, Phone_Number, Skills) values ('$eoi','$jobNumber', '$firstName', '$lastName', '$streetAddress', '$suburb', '$state', '$postcode', '$emailAddress', '$phoneNumber', '$skills')";


$result = mysqli_query($conn, $query);
    if($jobNumber = ''){
       $result = false;
    }
    if($firstName = ''){
    $result = false;
    echo "<p> Something is wrong with your First Name </p>";    
    }

    if($lastName = ''){
    $result = false;
    echo "<p> Something is wrong with your Last Name </p>";
    }

    if($streetAddress = ''){
    $result = false;
    echo "<p> Something is wrong with your Street Address </p>";
    }
    if($suburb = ''){
    $result = false;
    echo "<p> Something is wrong with your Suburb </p>";            
    }
    if($postcode = ''){
    $result = false;
    echo "<p> Something is wrong with your Postcode </p>";
    }
    if($email = ''){
    $result = false;
    echo "<p> Something is wrong with your Email </p>";     
    }
    if($phoneNumber = ''){
    $result = false;
        echo "<p> Something is wrong with your Phone Number </p>";
    }
    if($skills = ''){
    $result = false;
    echo "<p> Something is wrong with your Skills </p>";        
    }


if($result != mysqli_query($conn, $query)) {
    echo "<p>Something is wrong with ", $query, "</p>";
}else {
    echo "<p class=\"ok\">Successfully added a New EOI record</p>";
    }   
    }
}
        mysqli_close($conn);

我希望当用户输入有效数据时结果为Successfully added a new EOI record,但我收到错误消息。

1 个答案:

答案 0 :(得分:0)

  

首先,if语句中出现语法错误   if语句应为==而不是=

if($yourVariable == ''){
  echo "<p> Something is wrong with your yourVariable </p>";//no meaning of this line
  $result = false;
}

这意味着,如果您的variableempty,那么$resultfalse,您可以在最后一个条件中查看它

  

第二步,您正在检查数据库插入后的所有变量,需要在插入数据库之前进行检查