title: Display an Error Message in PHP form
body: <p>I have been making a Form in which Password is being Recovered in <code>reset.php</code>. I have already programmed according to which the Password changes after the recovery mail comes in. But the obstacle is just a small bug which doesn't display any message after clicking <strong>Change Password</strong> Button. Note*= The Password changes but only the Error/Success message doesn't display even if it is set with <code>if..else..</code>.</p>
  
  <p>Here's the code of <code>forgot.php</code> (Works perfectly and linked to <code>reset.php</code>)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
      ob_start();
      session_start();
      include('db-config.php');
  
      if(isset($_POST['forgot-submit'])){
          $recovery_user = $_POST['forgot-email'];
          $query = "SELECT * FROM RegisteredMembers WHERE userEmail='$recovery_user'";
          $output = mysql_query($query);
          $count = mysql_num_rows($output);
          $row = mysql_fetch_array($output);
          if($count==1){
              $error = false;
  
              // Mail the Recovery link
              $recovery_code = md5(uniqid(rand()));
              $mTo = $recovery_user;
              $mFrom = 'From: '.$website_details['name'].' Team '.'&lt;'.$website_details['email'].'&gt;';
              $mSubject = $website_details['name']." Account recovery Mail";
                  // Message
                  $mMsg[0] = "Hi ".$row['fname'].", \r\n";
                  $mMsg[1] = "This is the password recovery email which you have requested just few minutes before. &lt;b&gt;(If you havn't requested, you may kindly ingnore this Email)&lt;/b&gt;";
                  $mMsg[2] = "Here's your &lt;a href='$web_path/reset.php?recoverykey=$recovery_code'&gt;Password Recovery Link&lt;/a&gt;. Clicking it would allow you to change your existing password into a new one.";
                  $mFinMsg = $mMsg[0].$mMsg[1].$mMsg[2];
              $sendRecMail = mail( $mTo , $mSubject , $mFinMsg , $mFrom );
  
              // Add recovery code to Database
              $mysql = "UPDATE RegisteredMembers SET RecoveryCode='$recovery_code' WHERE userEmail='$recovery_user'";
              $result = mysql_query($mysql);
              if($result){
                  $error = false;
                  $forgotEmailMsg = "Thanks, Check your Email for recovering your password.";
              } else{
                  echo "Looks like there's a Disturbance and Load on server. Try again later.";
              }
          } else if(strlen($recovery_user)==0){
              $error = true;
              $forgotEmailMsg = "Please do not leave this field empty.";
          } else{
              $error = true;
              $forgotEmailMsg = "No such Email found in Database.";
          }
      }
  
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta name="robots" content="noindex" /&gt;
          &lt;link rel="stylesheet" type="text/css" href="assets/scripts/css/styles.css" /&gt;
          &lt;title&gt;Password Recovery&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form class="iqform" method="post" action="&lt;?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?&gt;" autocomplete="off"&gt;
              &lt;h3&gt;Password Recovery&lt;/h3&gt;
              &lt;label&gt;&lt;span class="text-danger"&gt;&lt;?php echo $forgotEmailMsg; ?&gt;&lt;/span&gt;&lt;input type="email" placeholder="Your registered Email" name="forgot-email" required /&gt;&lt;/label&gt;
              &lt;input type="submit" value="Next" name="forgot-submit" /&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php ob_end_flush(); ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Here's the code of <code>reset.php</code>. (Here's the page where actual problem persists)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
      ob_start();
      session_start();
  ?&gt;
  &lt;!DOCTYPE html&gt;
              &lt;head&gt;
                  &lt;meta name="robots" content="noindex" /&gt;
                  &lt;link rel="stylesheet" type="text/css" href="assets/scripts/css/styles.css" /&gt;
                  &lt;title&gt;Reset Password&lt;/title&gt;
              &lt;/head&gt;
  &lt;?php
      include('db-config.php');
      function show_change_pass_form(){
          // 
          ?&gt;
                  &lt;form class="iqform" method="post" action="&lt;?php echo $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; ?&gt;" autocomplete="off"&gt;
                      &lt;h3&gt;Change your Password&lt;/h3&gt;
                      &lt;label&gt;&lt;span class="text-danger"&gt;&lt;?php echo $passError ?&gt;&lt;/span&gt;&lt;input type="password" placeholder="New Password" name="new-pass" required /&gt;&lt;/label&gt;
                      &lt;label&gt;&lt;span class="text-danger"&gt;&lt;?php echo $Con_passError; ?&gt;&lt;/span&gt;&lt;input type="password" placeholder="Confirm Password" name="confirm-new-pass" required /&gt;&lt;/label&gt;
                      &lt;input type="submit" value="Change Password" name="pass-submit" /&gt;
                  &lt;/form&gt;
          &lt;?php
      }
      $recovery_code = $_GET['recoverykey'];
      /*if(empty($recovery_code)){
          echo 'Looks like you landed elsewhere. ';
      }*/
      $sql = "SELECT * FROM RegisteredMembers WHERE RecoveryCode='$recovery_code'";
      $result = mysql_query($sql);
      if($result){
          $count = mysql_num_rows($result);
          if( $count==1 &amp;&amp; !$recovery_code==0 ){
              if( isset($_POST['pass-submit']) ){
  
                  $pass = $_POST['new-pass'];
                  $Con_pass = $_POST['confirm-new-pass'];
  
                      // Confirmation
                          if($pass==$Con_pass){
                              if(strlen($pass)&lt;8){
                                  $error = true;
                              } else if(strlen($Con_pass)&lt;8){
                                  $error = true;
                              } else{
                                  $sql1 = "UPDATE RegisteredMembers SET password = '$pass' WHERE RecoveryCode = '$recovery_code'";
                                  $output = mysql_query($sql1);
                                  if($output==1){
                                       $error = false;
                                       $passError = "Password successfully changed. Feel free to Log In.";
  
                                       $zero = 0;
                                       $sql2 = "UPDATE RegisteredMembers SET RecoveryCode = '$zero' WHERE RecoveryCode = '$recovery_code'";
                                       $output2 = mysql_query($sql2);
                                          if($output2==1){
                                              $error = false;
                                          }
                                  }
                              }
                          } else if(!($pass==$Con_pass)){
                              $error = true;
                              $Con_passError = "The Password isn't matching. Be sure you remember the New Password.";
                          } else if(empty($pass)){
                              $error = true;
                              $passError = "Please do not keep the password empty.";
                          } else if(empty($Con_pass)){
                              $error = true;
                              $Con_passError = "Please do not keep this field empty.";
                          }
              }
  
              /*date_default_timezone_set("America/New_York");
              $nowtime = date("h:i:sa");
              $endtimestamp = mktime(date("H"),date("i")+1,date("s"));
              $endtime = date("h:i:sa",$endtimestamp);
              if($nowtime==$endtime){
                  $zero = 0;
                  $sql2 = "UPDATE RegisteredMembers SET RecoveryCode = '$zero' WHERE RecoveryCode = '$recovery_code'";
                  $output2 = mysql_query($sql2);
                      if($output2==1){
                          $error = false;
                      }
              }*/
  
              show_change_pass_form();
  
          } else if($count==0 || empty($recovery_code)) {
              echo "No such recovery code, please don't try Spamming around! ";
          }
      }
  ?&gt;
  &lt;?php ob_end_flush(); ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Even if the New Password and Confirm Password Error/Success messages are set, but I don't see any message after I click the <strong>Change Password</strong> Button. (Only Password Changes)</p>
  
  <p>No CSS styles are yet given. So, theirs no way of CSS problem of  <code>display:none</code>.</p>
  
  <p><strong>Actual Problem</strong> - I want the variables <code>$passError</code> and <code>$Con_passError</code> to be echoed properly.</p>
  
  <p>Thanks for the help I get, In advance!</p>