title: I'm trying to display errors when the form field are empty or not numeric values and stop the form from submitting when empty , What I'm doing wrong?
body: <pre><code>&lt;?php
  require_once "pdo.php";
  
  $failure = false;
  
  // Demand a POST parameter
  if (isset($_POST['make']) &amp;&amp; isset($_POST['year']) &amp;&amp; isset($_POST['mileage'])) {
  
      // if (empty($_POSt['make']) &amp;&amp; empty($_POST['year']) &amp;&amp; empty($_POST['mileage'])) {
          // $failure = "Mileage and year must be numeric";
          // return false;
      // }
      $sql = "INSERT INTO autos (make, year, mileage) VALUES (:mk, :yr, :mi)";
  
      $stmt = $pdo-&gt;prepare($sql);
      $stmt -&gt; execute(array(
          ':mk' =&gt; $_POST['make'],
          ':yr' =&gt; $_POST['year'],
          ':mi' =&gt; $_POST['mileage']));
      // $row = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
  
      $make = $_POST['make'];
      $year = $_POST['year'];
      $mileage = $_POST['mileage'];
  
      if (empty($_POST['make'])) {
          $_SESSION['make'] = $failure = "Make is required";
      }else {
          if(!empty($_POST['make']) &amp;&amp; is_numeric($_POST['year']) &amp;&amp; is_numeric($_POST['mileage'])){
              echo '&lt;p style="color: green"&gt;Record inserted'."&lt;/p&gt;\n";
          }else {
  
              if(is_numeric($_POST['year']) === false &amp;&amp; is_numeric($_POST['mileage']) === false){
                  $failure = "Mileage and year must be numeric";
                  header("Location: autos.php?name=".urlencode($_POST['who']));
                  return false;
              }
          }
      }
  
  }
  // If the user requested logout go back to index.php
  if ( isset($_POST['logout']) ) {
      header('Location: index.php');
      return;
  }
  
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Automobile Tracker&lt;/title&gt;
  &lt;?php require_once "bootstrap.php"; ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="container"&gt;
  &lt;!-- &lt;h1&gt;Tracking Autos for &lt;a href="#"&gt;&lt;/a&gt;&lt;/h1&gt; --&gt;
  &lt;?php
  if ( isset($_REQUEST['name']) ) {
      echo "&lt;h1&gt;Tracking Autos for  ";
      echo htmlentities($_REQUEST['name']);
      echo "&lt;/a&gt;&lt;/h1&gt;\n";
  }
  if(!empty($_POST['make']) &amp;&amp; is_numeric($_POST['year']) &amp;&amp; is_numeric($_POST['mileage'])){
      echo '&lt;p style="color: green"&gt;Record inserted'."&lt;/p&gt;\n";
  }
  
  if ( $failure !== false ) {
      // Look closely at the use of single and double quotes
      echo('&lt;p style="color: red;"&gt;'.htmlentities($failure)."&lt;/p&gt;\n");
  }
  ?&gt;
  &lt;form method="post"&gt;
  &lt;p&gt;Make:
  &lt;input type="text" name="make" size="60"/&gt;&lt;/p&gt;
  &lt;p&gt;Year:
  &lt;input type="text" name="year"/&gt;&lt;/p&gt;
  &lt;p&gt;Mileage:
  &lt;input type="text" name="mileage"/&gt;&lt;/p&gt;
  &lt;input type="submit" value="Add"&gt;
  &lt;input type="submit" name="logout" value="Logout"&gt;
  &lt;/form&gt;
  &lt;h2&gt;Automobiles&lt;/h2&gt;
  &lt;ul&gt;
  &lt;?php 
      $stmt = $pdo-&gt;query("SELECT make, year, mileage FROM autos");
      while($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
          echo "&lt;li&gt;";
          echo($row['year']);
          echo " ";
          echo($row['make']);
          echo " / ";
          echo($row['mileage']);
          echo "&lt;/li&gt;";
      }
  ?&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So far if I'm trying to submit the form with empty field i get the error "Make is required", but it's still submitting the form , and also If i add something into make field and nothing in year and mileage field i don't get the error "Mileage and year must be numeric" even if i add something that is not numeric i don't get the error for them.</p>
  
  <p><strong>Please let me know what i did wrog (I just started learning PHP).
  Thank you in advance.</strong></p>