0

我在网上查看过,但所有 $_POST 和 $_GET 示例都是针对文本而不是数字。这不是连接到数据库。它不需要表单验证。它只是在我的系统上本地运行的一个单页项目。我想让它尽可能简单。

目标是有一个输入,您可以在其中输入您的小时工资。例如 15。然后,当您按下提交时,它会返回到同一页面,其中包含您每天、每周、每月和每年赚多少钱的漂亮列表。

任何帮助将不胜感激。

<p>Input your Hourly Pay</p>
<form method="GET" action="" >
<input name="num1" type="text" >
<input type="submit" name="submit" value="Submit">
</form>


<?php

if ($_GET['num1']) {
    $rate = $_GET['num1'];
    return $rate;
}    

$result_day= $rate * 8;
$result_week = $rate * 8 * 5;
$result_month = $rate * 8 * 5  * 4;
$result_year = $rate * 8 * 5  * 4  * 12;

echo "Rate: " . $rate . "<br>";
echo "Daily: " . $result_day . "<br>";
echo "Weekly: " . $result_week . "<br>";
echo "Monthly: " . $result_month . "<br>";
echo "Yearly: " . $result_year . "<br>";

?>
4

2 回答 2

0

我做了一些更正,但计算仍然是你原来的:

<?php

if (isset($_GET['num1'])) {
    $rate = $_GET['num1'];   

$result_day= $rate * 8;
$result_week = $result_day * 5;
$result_month = $result_week  * 4;
$result_year = $result_month  * 12;

echo "Rate: " . $rate . "<br>";
echo "Daily: " . $result_day . "<br>";
echo "Weekly: " . $result_week . "<br>";
echo "Monthly: " . $result_month . "<br>";
echo "Yearly: " . $result_year . "<br>";

}else{
 echo  "Please enter your rate!";
}
于 2013-02-25T06:47:42.807 回答
0

Use the onchange event with Javascript on any of the fields. You can then use Javascript to calculate the rest of the values and update those fields.

No PHP required. No time lag with a new page required. Users will love it.

于 2013-02-25T07:13:55.920 回答