Php 如果用户填写了字段,则不会显示输出

Php 如果用户填写了字段,则不会显示输出,php,html,Php,Html,我应该输入什么代码,以便我的输出“您的汽车成本”不会显示 我一直在想该放什么,但失败了 <?php // define variables and set to empty values $costErr = $modelErr = ""; $cost = $model = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["cost"])) { $costErr = "Cost is requ

我应该输入什么代码,以便我的输出“您的汽车成本”不会显示
我一直在想该放什么,但失败了

<?php
// define variables and set to empty values
$costErr = $modelErr = "";
$cost = $model = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {

  if (empty($_POST["cost"])) {
    $costErr = "Cost is required";
  } else {
    $cost = test_input($_POST["cost"]);
  }

  if (empty($_POST["model"])) {
    $modelErr = "Model is required";
  } else {
    $model = test_input($_POST["model"]);
  }

}
function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

当用户在字段中输入某个值时,这是输出,但是如果用户不在字段中输入值,则此输出不应显示,我该如何处理

<?php
if (isset($_POST["age"]) && $_POST["age"] === "1 Year" && $_POST["conditon"] === "Yes") { 
  if ($_POST["age"] === "1 Year" && $_POST["conditon"] === "Yes") {
    echo "Your car Costs " .$cost;
    echo "<br>";
    echo "The model of your car is " .$model;
    echo "<br>";
    $price = $cost - ($cost * .20);
    echo "Your car costs in good condition " .$price;
  } else if($_POST["age"] === "1 Year" && $_POST["conditon"] === "No") {
    echo "Your car Costs " .$cost;
    echo "<br>";
    echo "The model of your car is " .$model;
    echo "<br>";
    $price = $cost - ($cost * .20) - ($cost * .10);
    echo "Your car costs in bad condition " .$price;
  }
}
?>

if语句中的
$\u POST[“conditon”]==“Yes”
有两次-在外部和内部
if
语句中,因此如果这不是真的,它将不会进入
else if
块。如果我能正确理解你想要什么:将它从外部移除。作为旁注,那些
test\u input()
函数基本上毫无价值。哦,谢谢:)没有注意到这一点,但我仍然不希望在字段为空时输出。