【发布时间】:2016-05-21 12:15:14
【问题描述】:
我有我的 PHP 代码:
<?php
$num1= $_REQUEST["number1"];
$num2= $_REQUEST["number2"];
$arithmetic = $_POST['arithmetic'];
switch ($arithmetic) {
case "addition":
$answer = $num1+$num2;
echo "<p>$num1 added with $num2 is " . number_format($answer,2) . "</p>";
break;
case "subtraction":
$answer = $num1-$num2;
echo "<p>$num2 subtracted from $num1 is " . number_format($answer,2) . "</p>";
break;
case "multiplication":
$answer = $num1*$num2;
echo "<p>$num1 multiplied by $num2 is " . number_format($answer,2) . "</p>";
break;
case "division":
$answer = $num1/$num2;
echo "<p>$num1 divided by $num2 is " . number_format($answer,2) . "</p>";
break;
case "modulus":
$answer = $num1%$num2;
echo "<p>The remainder of $num1 divided by $num2 is " . number_format($answer,2) . "</p>";
break;
}
?>
<br>
<form action="calcD.html" target="iframeMain">
<input type="submit" value="go back">
</form>
<?php
echo "<HR>";
highlight_file("calcD.php");
?>
以及我的 HTML 代码:
<html>
<head>
<link href="reset.css" rel="stylesheet" type="text/css">
<link href="css3.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Scada:400,700' rel='stylesheet' type='text/css'>
</head>
<body>
<h2>Dropdown Calculator</h2>
<form action="calcD.php" method="POST" target="iframeMain" autocomplete="off">
<p>Number 1:<input type="text" name="number1"></p>
<p>Number 2:<input type="text" name="number2"></p>
<h3>Type of Arithmetic</h3>
<select name="arithmetic">
<option name="addition">Addition</option>
<option name="subtraction">Subtraction</option>
<option name="multiplication">Multiplication</option>
<option name="division">Division</option>
<option name="modulus">Modulus</option>
</select>
<input type="submit" name="compute" value="Compute">
</form>
<a href="assignment3.html" target="iframeMain">Back to Menu</a>
</body>
</html>
但是当我尝试使用我的程序时,没有显示答案。我检查了多个站点,我的 HTML 和 PHP 都没有错误,但我的答案没有显示。我什至尝试对每个程序使用 If 和 Elseif 语句。是否有我为他们缺少的链接?
编辑:我需要使用 switch (strtolower($arithmetic)) 而不是标准开关来允许它显示。
【问题讨论】:
-
我添加了这个,但仍然无法显示我的答案。
-
然后更新您的问题。