如何在提交表单时打印所有发布结果

时间:2014-02-06 15:03:10

标签: php

这段代码有什么问题?它没有回应答案。

<?php
     $num1=$_POST['fnum'];
     $num2=$_POST['snum'];

     $sum=$num1 + $num2;
     $diff=$num1 - $num2;
     $prod=$num1 * $num2;
     $quo=$num1 / $num2;
     $mod=$num1 % $num2;


     echo "The sum is " .$sum. <br>;
     echo "The differense is " .$diff. <br>;
     echo "The product is " .$prod. <br>;
     echo "The quotient is " .number_format($quo,2). <br>;
     echo "The remainder is " .$mod. <br>;
  ?>    

3 个答案:

答案 0 :(得分:1)

您正在以错误的方式连接<br>标记。

echo "The sum is " .$sum. <br>;

应该是:

echo "The sum is " .$sum. "<br>";

答案 1 :(得分:1)

假设使用POST方法从表单中获取数字105

给出以下结果:(来自下面的固定版本)

  

总和是15
  区别是5
  产品是50
  商是2.00
  余数为0

你错过了联系人的引用。

I.e。:

echo "The sum is " .$sum.  <br> ;
             missing "    ^    ^

以及其他人。

这没有解析错误:

<?php
     $num1=$_POST['fnum'];
     $num2=$_POST['snum'];

     $sum=$num1 + $num2;
     $diff=$num1 - $num2;
     $prod=$num1 * $num2;
     $quo=$num1 / $num2;
     $mod=$num1 % $num2;

     echo "The sum is " .$sum. "<br>";
     echo "The differense is " .$diff. "<br>";
     echo "The product is " .$prod. "<br>";
     echo "The quotient is " .number_format($quo,2). "<br>";
     echo "The remainder is " .$mod. "<br>";
?>

它也可以这样做,给出相同的输出格式:

<?php
     $num1=$_POST['fnum'];
     $num2=$_POST['snum'];

     $sum=$num1 + $num2;
     $diff=$num1 - $num2;
     $prod=$num1 * $num2;
     $quo=$num1 / $num2;
     $mod=$num1 % $num2;

     echo "The sum is " .$sum;
     echo "<br>";
     echo "The differense is " .$diff;
     echo "<br>";
     echo "The product is " .$prod;
     echo "<br>";
     echo "The quotient is " .number_format($quo,2);
     echo "<br>";
     echo "The remainder is " .$mod;
?>

答案 2 :(得分:0)

如果我们能够看到您用来发布到PHP的代码,那就太好了。通过快速扫描您所放置的内容,似乎可能是您的问题。确保以一种可以在计算中使用的方式使用名称fnum和snum进行发布。我建议如下包装输入:

$num1 = floatval($_POST['fnum']);
$num2 = floatval($_POST['snum']);

确保你输入的数字是一个数字。