PHP-询问用户输入-计算

PHP-询问用户输入-计算,php,Php,我一直在努力使这个简单的程序工作,但由于某种原因,我没有得到任何结果。如有任何建议,将不胜感激。谢谢 <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> Price of the Meal <input value="100" type="text" name="meal"><br> Tip <input value="20" type="t

我一直在努力使这个简单的程序工作,但由于某种原因,我没有得到任何结果。如有任何建议,将不胜感激。谢谢

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    Price of the Meal
    <input value="100" type="text" name="meal"><br>
    Tip
    <input value="20" type="text" name="tip">
    <input type="submit" name="submit">


    <?php
    $meal = $_POST['meal'];
    $tip = $_POST['tip'];

    $total_amount = check($meal, 10, $tip);

    function check($meal, $tax, $tip) {

        $tax_amount = $meal * .10;

        $tip_amount = $meal * ($tip / 100);

        $total_amount = $meal + $tax_amount + $tip_amount;
        echo "Price of the meal " . $meal . "\n";


        echo "tax_amount " . $tax_amount . "\n";
        echo "tip_amount " . $tip_amount . "\n";

        return $total_amount;
    }

    echo "Total " . $total_amount;
    ?>

代码运行时变化不大

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    Price of the Meal
    <input value="100" type="text" name="meal"><br>
    Tip
    <input value="20" type="text" name="tip">
    <input type="submit" name="submit">


    <?php
    $meal = $_POST['meal'];
    $tip = $_POST['tip'];

    $total_amount = check($meal, 10, $tip);

    function check($meal, $tax, $tip) {

        $tax_amount = $meal * .10;

        $tip_amount = $meal * ($tip / 100);

        $total_amount = $meal + $tax_amount + $tip_amount;
        echo "Price of the meal " . $meal . "\n";


        echo "tax_amount " . $tax_amount . "\n";
        echo "tip_amount " . $tip_amount . "\n";

        return $total_amount;
    }

    echo "Total " . $total_amount;
    ?>
$tax_amount = $meal * ($tax/100);
并添加条件

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    Price of the Meal
    <input value="100" type="text" name="meal"><br>
    Tip
    <input value="20" type="text" name="tip">
    <input type="submit" name="submit">


    <?php
    $meal = $_POST['meal'];
    $tip = $_POST['tip'];

    $total_amount = check($meal, 10, $tip);

    function check($meal, $tax, $tip) {

        $tax_amount = $meal * .10;

        $tip_amount = $meal * ($tip / 100);

        $total_amount = $meal + $tax_amount + $tip_amount;
        echo "Price of the meal " . $meal . "\n";


        echo "tax_amount " . $tax_amount . "\n";
        echo "tip_amount " . $tip_amount . "\n";

        return $total_amount;
    }

    echo "Total " . $total_amount;
    ?>
 if (isset($_POST['meal']) && isset($_POST['tip']) && $_POST['meal'] > 0 && $_POST['tip'] > 0) {
  echo "Price of the meal " . $meal . "\n";
  echo "tax_amount " . $tax_amount . "\n";
  echo "tip_amount " . $tip_amount . "\n";
}


if (isset($_POST['meal']) && isset($_POST['tip']) && $_POST['meal'] > 0 && $_POST['tip'] > 0)
  echo "Total " . $total_amount;

你期望得到什么样的结果?您得到了什么结果(包括浏览器显示和日志文件)?其他简单的php“Hello world”样式的页面是否有效?我只想计算税额,以及用户输入膳食后的小费金额。谢谢你得到了什么结果而不是你所期望的?我没有在我的本地网络机器上安装php,我无法运行你的代码,所以我不知道它在做什么——你给它的各种输入结果是什么?我可能可以浏览一下,看看你是否告诉我你的输入是什么,输出是什么,以及预期的输出是什么。在结果上粘贴一个视图源以便我们查看。如果它根本没有提交,考虑关闭你的元素。不确定浏览器是否对此过于挑剔。表单中缺少Hi标记