【发布时间】:2019-12-02 05:53:33
【问题描述】:
如果其中 2 个为真,则两个错误链接都会显示并且消息彼此重叠,如果输入为 0,如果验证空输入的语句也会显示 此外,如果输入不是数字但另一个输入是数字 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 语句用于验证输入是否为数字
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>");
}
第三个 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>");
}
this 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{
【问题讨论】:
-
你能解释一下你期望的结果和你遵循的程序吗?
-
如果任何一个为真,它将显示一条错误消息。如果没有正确处理 $first $second 和 $operator
标签: php html if-statement