Link to code 由于无法除以0,因此我的php将显示错误消息,但是,尽管它显示错误消息,但它还会显示如果不除以0则应显示的表。 ?
<!DOCTYPE html>
<html>
<head>
<title>Math Calculations!</title>
</head>
<body>
<!-- Background color selection for site-->
<body style="background-color:#ACDDE3;">
<?php
我的价值观
// input values
$firstInt = $_POST["firstInt"];
$secondInt = $_POST["secondInt"];
$calc = $_POST["calc"];
$result = 0;
// inc-math-problems.php
include ("juarez-inc-calc.php");
声明
elseif ($calc == "Multiplication") {
$calculation = "Multiplication";
$prefix = "The product of";
$result = prodIntegers($firstInt, $secondInt);
}
elseif ($calc == "Divison") {
$calculation = "Divison";
$prefix = "The quotient of";
目标
if ($secondInt == 0){
print("Error: You can't divide by zero
$result = "invalid";
}
else{
$result = quotIntegers($firstInt, $secondInt);
}
打印语句
print("<style>
table, th, td {
border: 1px solid black;
padding: 5px;
}
table {
border-spacing: 5px;
}
</style>
</head>
<body>
<h2>The Results</h2>
<table>
<tr>
<th>Operation</th>
<th>Result</th>
</tr>
<tr>
<td>$calculation</td>
<td>$result</td>
</tr>
</table>");
print("<a href=\"juarez-calculations.html\"> Return to form </a>");
?>
</body>
</html>
答案 0 :(得分:0)
尝试一下:
if ($secondInt == 0){
print("Error: You cannot divide by zero");
$result = "invalid";
}
else{
$result = quotIntegers($firstInt, $secondInt);
}
答案 1 :(得分:0)
问题出在您的目标块中:-
if ((int)$secondInt === 0){
print("Error: You can't divide by zero");
$result = "invalid";
}
else{
$result = quotIntegers($firstInt, $secondInt);
}
if($result!="invalid"){
//////print your table here
}