I have being trying to make this simple program work, but for some reason, I am not getting any results. Any suggestions will be appreciated. Thanks.
<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;
?>
The code is working with little change
$tax_amount = $meal * ($tax/100);
and add conditions
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.