How to display individual error messages next to empty or incorrect form input fields in PHP? If the form is successfully submitted, how to then refresh the page after a few seconds and redirect the user back to a previous page?

**PHP (Front)**:

```
<form id="application" method="post" action="processing.php" novalidate="novalidate">
    <fieldset>
        <p>
            <legend>Application Form</legend><p>
                <label for="fname">Name</label>
                <input type="text" name="fname" id="fname" required="required" />
        </p>
    </fieldset>
</form>

```

**PHP (Back)**:

```
<?php
    function sanitise_input($data) {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
    }
    require_once ("settings.php");
    $conn = @mysqli_connect(
      $host,
      $user,
      $pwd,
      $sql_db
    );
if ($conn) {
      if (isset($_POST["fname"])) {
        $fname = sanitise_input($_POST["fname"]);
      }
        else {
          mysqli_close($conn);
          header("location:application.php");
        }
else {
          mysqli_close($conn);
          header("location:application.php");
        }
      $query = "CREATE TABLE IF NOT EXISTS application (
        fname VARCHAR(50) NOT NULL)";
      $result = mysqli_query ($conn, $query);
      if (!$result) {
        echo "<p>Error!</p>";
      }
    }
    if (!$conn) {
      echo "<p>Failed!</p>";
    }
      else {
        $sql_table = "application";
        $query = "INSERT INTO $sql_table (fname) VALUES ('$fname')";
      $result = mysqli_query($conn, $query);
      if (!$result) {
        echo "<p>Error!", $query, "</p>";
      }
        else {
          $id = "SELECT * FROM application ORDER BY id DESC LIMIT 1";
          $idresult = mysqli_query($conn, $id);
          while ($row = mysqli_fetch_assoc($idresult)) {
            echo "<p>You are applicant #",$row["EOInumber"],"</p>";
          }
        }
      mysqli_close($conn);
    }
    ?>

```