如何显示PHP和HTML程序的答案?

如何显示PHP和HTML程序的答案?,php,html,web,Php,Html,Web,我有我的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,

我有我的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语句。有没有一个链接我错过了他们


编辑:我需要使用
开关(strtolower($算术))
而不是标准开关来允许它显示。

错误在您的选项中。你有

减法

它们应该有值,而不是名称:

减法

试试:

$num1= $_POST["number1"];
$num2= $_POST["number2"];

使用
开关(strtolower($算术))
。您的算术后置值中有大写字母…

我没有看到“选择”:我添加了此选项,但仍然无法显示我的答案。然后更新您的问题。我更改了代码;仍然不起作用,但仍然没有错误。谢谢你的发帖!我也试过这个!当我在众多解释开关的网站中筛选时,有人告诉我不要使用value和name。但是,这不起作用。
name
不是选项的有效属性。建议您使用它的站点是错误的。至于您的代码,我已经在本地进行了测试,并且在上面的更改中,它可以正常工作<代码>2加上2等于4.00则必须是我的CSS或页面在我的iframe中的显示方式,因为当我单击“计算”按钮时,只会显示“返回”按钮。在您的开关中,添加一个默认条件,然后查看是否仍然没有输出。啊,就是这样!非常感谢。这只是因为正如我在回答中所说,您错误地使用了
名称
而不是
。没有值的选项将使用文本作为值(请注意,name属性完全不起任何作用)。如果你像我描述的那样修复了这个问题,代码就会正常工作!