title: Why is my error message not echoing to the screen?
body: <p>When the user submits a form, the PHP will check to see if the $post was empty, if so, it will set an $error_message variable; thus database INSERT query will not execute. I then attempt to show the error message further on in the code, however it will not display. I have been trying to figure this out for hours and I still cannot find the solution. The funny thing is, this used to work, however I must have implemented something in this file which is preventing the code to execute correctly.</p>
  
  <p>Why is my error message not echoing to the screen (last few lines of code show attempt to echo the error_message)?</p>
  
  <pre><code>&lt;?php require("inc/db.php"); ?&gt;
  &lt;?php include("inc/functions.php"); ?&gt;
  &lt;?php include ("inc/ChromePhp.php"); ?&gt;
  &lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  ini_set("html_errors", 1);
  session_start();
  if(!isset($_GET['id'])) {
    header("Location: ?id=".getUserId($_SESSION['U_Email']));
  }
  if(isset($_SESSION["U_Email"])) {
    $usersData = getUserInfo($_GET['id']);
    $postCount = getPostCount($_GET['id']);
  } else {
    header('Location: login.php');
  }
  
  if($_SERVER["REQUEST_METHOD"] == "POST") {
    $post = trim(filter_input(INPUT_POST,"user_post",FILTER_SANITIZE_SPECIAL_CHARS));
  
    if($post == "") {
      $error_message = "Please enter something before submitting";
    }
  
    if(!isset($error_message)) {
      $post = $db-&gt;real_escape_string($post);
      $postStore = $db-&gt;query("INSERT INTO `Post`(P_Body, P_Dateadded, User_U_ID) VALUES ('{$post}', NOW(), '{$_SESSION['U_ID']}' )");
    }
  }
  
  $dashNav = true;
  $cap = true;
  $pageTitle = 'Profile';
  $name = $usersData['U_Forename'] . " " . $usersData['U_Surname'];
  $gender = $usersData['U_Gender'];
  $bio = $usersData['U_Biography'];
  $team = $usersData['U_Team'];
  $city = $usersData['U_City'];
  include("inc/header.php");
  ?&gt;
  
    &lt;?php if(userExists($_GET['id'])) { ?&gt;
    &lt;section&gt;
      &lt;div class="wrapper"&gt;
        &lt;?php
        if($_SESSION['U_ID'] != $_GET['id']) {
          $testFollow = "SELECT `Following`.F_ID, `Following`.U_ID FROM `Following`
          WHERE U_ID = '{$_SESSION['U_ID']}' AND F_ID = '{$_GET['id']}'";
          $testFollowResult = $db-&gt;query($testFollow);
          if ($testFollowResult-&gt;num_rows &gt; 0) {
            echo "&lt;button class='lift' href='#'&gt;Unfollow Driver&lt;/button&gt;";
          } else {
            echo "&lt;button class='lift' href='#'&gt;Follow Driver&lt;/button&gt;";
          }
        }
        ?&gt;
  
        &lt;?php if (isset($error_message)) {
          // This code will not echo!
          echo "&lt;h2&gt;".$error_message."&lt;/h2&gt;";
        }
    ?&gt;
  &lt;/div&gt;
  
  &lt;div class="section-b"&gt;
   &lt;div class="grid"&gt;
    &lt;div class="row"&gt;
     &lt;div class="col-wd-12"&gt;
      &lt;div class="col"&gt;
       &lt;form id="share" name="share" action="profile.php" method="post"&gt;
       &lt;textarea id="post" name="user_post" placeholder="What's happening?"&gt;    &lt;/textarea&gt;
       &lt;span id="errorpost" class="error"&gt;You must input something something before sending&lt;/span&gt;
       &lt;?php
       echo "&lt;div class='g-recaptcha' data-     sitekey='6LfNTB0TAAAAAKEw9zfnFzvGCXF9MuYTkdB144x1
       '&gt;&lt;/div&gt;"; ?&gt;
     &lt;button onclick="return postCheckValidate();"        type="submit"&gt;Share&lt;/button&gt;
   &lt;/form&gt;
       &lt;/div&gt;
      &lt;/div&gt;
     &lt;/div&gt;
    &lt;/div&gt;
   &lt;/div&gt;
  &lt;?php } ?&gt;
  </code></pre>