title: How to save field form in database with required fields
body: <p>Hello I'm figuring how to save the field entered into database when there's no field required left.</p>
  
  <p>I can already save from database with php and mysqli, but I don't want to include the null/blank value from the database which is why I'm using required field but I don't know how to use it. What I wanted to do is when all the required field is not null or has already value in it, it will gonna save from the database. </p>
  
  <p>I don't know what to put on 
           form method=post action="HERE"</p>
  
  <p>PS: Sorry for bad english.</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt; 
  &lt;html&gt;
  &lt;head&gt;
  &lt;style&gt;
  .error {color: #FF0000;}
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt; 
  
  &lt;?php
  // define variables and set to empty values
  $nameErr = "";
  $name = "";
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
     if (empty($_POST["name"])) {
       $nameErr = "Name is required";
     } else {
       $name = test_input($_POST["name"]);
       // check if name only contains letters and whitespace
       if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
         $nameErr = "Only letters and white space allowed"; 
       }
     }
  }
  
  function test_input($data) {
     $data = trim($data);
     $data = stripslashes($data);
     $data = htmlspecialchars($data);
     return $data;
  }
  ?&gt;
  
  
  &lt;p&gt;&lt;span class="error"&gt;* required field.&lt;/span&gt;&lt;/p&gt;
  &lt;form method="post" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;"&gt; 
     Name: &lt;input type="text" name="name" value="&lt;?php echo $name;?&gt;"&gt;
     &lt;span class="error"&gt;* &lt;?php echo $nameErr;?&gt;&lt;/span&gt;
     &lt;br&gt;&lt;br&gt;
     &lt;input type="submit" name="submit" value="Submit"&gt; 
  &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>