Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基本php表单计算问题_Php_Forms - Fatal编程技术网

基本php表单计算问题

基本php表单计算问题,php,forms,Php,Forms,我正在做一些可能很愚蠢的事情,想知道是否有人能指出我做错了什么。自学php,在这样做的过程中,我试图制作一个工资计算器。它给了我这些结果: Your results: 29 years old earning $205per day working $5days a week at a Your total earned money at age 65 is $0. While your yearly income is 49200 显然,总收入数字并不正确。0是不对的 这是完整的代码 &l

我正在做一些可能很愚蠢的事情,想知道是否有人能指出我做错了什么。自学php,在这样做的过程中,我试图制作一个工资计算器。它给了我这些结果:

Your results:
 29 years old earning
$205per day working
$5days a week at a
Your total earned money at age 65 is $0.
While your yearly income is
49200
显然,总收入数字并不正确。0是不对的

这是完整的代码

<?php

//get the values from the $_POST array

$age = $_POST['age'];
$days = $_POST['days'];
$pay = $_POST['pay'];



//calculate the total:

$howold = 65 - $age;
$retireageincome = $yearlyincome * $howold;
$yearlyincome = $pay * $days * 4 * 12;




//print out results

print "<p>Your results:<br>
<span class=\"number\">$age</span> years old earning <br>
$<span class=\"number\">$pay</span>per day working <br>
$<span class=\"number\">$days</span>days a week at a<br>
Your total earned money at age 65 is $<span class=\"number     
\">$retireageincome</span>.<br>
While your yearly income is <br>
<span class=\"number\">$yearlyincome</span>  </p>";

?>

</body>
</html>

您试图在
$yearlyincome
的值已知之前使用
$yearlyincome

命令的顺序很重要。移动

$yearlyincome = $pay * $days * 4 * 12;

位于使用
$yearlyincome
的行之前,您应该看到一个非0值。

仔细查看您的代码和/或打开错误报告,您将看到您的问题。$retireageincome在$yearlyincome之后计算。。。我想您的订单已经取消了…谢谢。事实上,我甚至没有意识到变量的顺序是重要的。