Php 正在验证用户输入的状态是否正确

Php 正在验证用户输入的状态是否正确,php,html,if-statement,Php,Html,If Statement,如果其中2个为真,则会显示错误链接,并且消息彼此重叠;如果输入为0,则会显示验证空输入的if语句 另外,如果输入不是数字,但另一个输入是数字,php仍会计算,但只会返回您给出的数字加上顶部的错误代码,我如何修复 第一条语句是验证是否有任何值为0,以及操作是否为除法以给出错误 if ($first == 0) { if ($operation == "Division") print("<h1>ERROR</h1> <p class=\"messa

如果其中2个为真,则会显示错误链接,并且消息彼此重叠;如果输入为0,则会显示验证空输入的if语句 另外,如果输入不是数字,但另一个输入是数字,php仍会计算,但只会返回您给出的数字加上顶部的错误代码,我如何修复

第一条语句是验证是否有任何值为0,以及操作是否为除法以给出错误

if ($first == 0)
{ if ($operation == "Division")
  print("<h1>ERROR</h1>
        <p class=\"message\">YOU CAN NOT DIVIDE BY ZERO</p>");
}


else if($second == 0)
{ if ($operation =="Division")
  print("<h1>ERROR</h1>
        <p class=\"message\"> YOU CAN NOT DIVIDE BY ZERO</P>");
}
if($first==0)
{if($operation==“Division”)
打印(“错误

不能被零除“

”; } else if($second==0) {if($operation==“Division”) 打印(“错误

不能被零除“

”; }
此if语句用于验证输入是否为数字

if (!is_numeric($first) or !is_numeric($second))
{
print("<h1> Error one or more inputs are not numbers</h1>" . "<p class=\"backlink\"><a href=\"calculator.html\">Go Back</a></p>");


}
如果(!是数字($first)或!是数字($second))
{
打印(“错误一个或多个输入不是数字”。

”; }
第三个if语句用于验证正数

else if($first < 0 or $second < 0)
{
 print("<h1> Error one of more of your numbers is a negative</h1>" . "<p class=\"backlink\"><a href=\"calculator.html\">Go Back</a></p>");

}
else if($first<0或$second<0)
{
打印(“错误一个或多个数字为负数”。

”; }
此if语句验证空输入

   if (empty($first) or empty($second))
  {
 print("<p class=\"message\"> One or more input field is empty </p>" . "<p class=\"backlink\"><a href=\"calculator.html\">Go Back</a></p>");

}else{
if(空($first)或空($second))
{
打印(“

一个或多个输入字段为空

”; }否则{
@irvdtcc查看代码,我知道您需要检查多个条件,只有在所有条件都为真时才显示结果

要检查的标准 1) $first和$second是大于0的数字 2) $first和$second输入不为空

最好的方法是对每个条件使用标志,如下所示

<?php
$fl_positive=0;
$fl_num=0;
$fl_empty=0;
$error_message="";

//check if number is empty -- empty is true of $first=0 or $first="". In either case //empty($first) will result in true.
if(empty($first) or empty($second)){
  $fl_empty=1;
  $error_emssage . = "First or Second number is empty or zero";
}
elsif($first<0) or ($second<0)) {
  $fl_positive=1;
  $error_message . = " First or Second number is Negative";
}

//Check all criteria in the same manner

if($fl_positive==1) or ($fl_num==0) or ($fl_empty=0)){
  echo $error_message;
}
?>

您能解释一下您期望的结果和遵循的过程吗?如果任何结果为真,它将显示一条错误消息。如果处理$first$second和$OPERATOR的错误为:语法错误,在C:\xampp\htdocs\calculator.php第17行的意外“=”是我用文件上的前一个if语句替换它时得到的结果第17行是$error_消息。=“第一或第二行为负数”;