title: PHP : Captcha verification code not working properly;
body: <p>I am creating a very simple Captcha verification process.</p>
  
  <p>(When a user tries to log into my website 3 times, without success, he is re-directed to the Captcha Page  (captcha.php), to verify that he is not a spam-bot)</p>
  
  <p>The Captcha value itself is randomly generated from a string of letters and numbers.   6 digits in all.</p>
  
  <p>And then, I compare this value with the value entered by the user into a text-box.  if the values match, the user may proceed. If not, the page reloads, an error message is displayed, and a new captcha is generated.</p>
  
  <p>Very simple. No javascript, no ajax. </p>
  
  <p>Except for one thing :  the Captcha is NOT re-directing if the user provides the correct value.</p>
  
  <p>Instead, it gives the error message every time.</p>
  
  <pre><code>  &lt;?php session_start();
  
     include 'database_connect.php';
  
     function getRandomString($length)  {
     $validCharacters =  
     "ABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
      $validCharNumber = strlen($validCharacters);
      $result = "";
  
      for ($i = 0; $i &lt; $length; $i++) {
      $index = mt_rand(0, $validCharNumber - 1);
      $result .= $validCharacters[$index];
      }
      return $result; }
  
      $captcha_value = getRandomString(6);
  
      ?&gt;
  
     &lt;!DOCTYPE html&gt;
     &lt;html&gt;
     &lt;head&gt;
          &lt;META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"&gt;
          &lt;META HTTP-EQUIV="Cache-Control" CONTENT="no-store"&gt;
          &lt;META HTTP-EQUIV="Pragma" CONTENT="no-cache"&gt;
          &lt;META HTTP-EQUIV="Expires" CONTENT="0"&gt;
          &lt;META CHARSET="UTF-8"&gt;      
          &lt;title&gt;Captcha Test&lt;/title&gt;         
    &lt;/head&gt;
   &lt;body&gt;
      &lt;fieldset&gt;&lt;legend&gt;CAPTCHA :&lt;/legend&gt;
  
       &lt;?php 
              if (isset($_POST['submit'])) {
  
                  $post_captcha = $_POST['captcha'];
  
                  if ($post_captcha == $captcha_value) {
  
                  $clear_failed_logins =  mysqli_query($conn,("Delete FROM 
                                          login_attempts where login = 
                                          '$_POST[login]'")) 
                                          or die(mysqli_error($conn)); 
  
                  header ("Location: /example.com/login.php");    
                  exit();     
              }
              else {
  
              echo "&lt;p style='color:red; font-weight:bold;'&gt;The value you  
                     entered is not correct! Please try again.&lt;/p&gt;";
               }
            }
          ?&gt; 
  
          &lt;p&gt;Please input the characters you see into the text-box below :&lt;/p&gt;
          &lt;p&gt;  &lt;?= $captcha_value ?&gt; &lt;/p&gt;
          &lt;form method="POST" action="captcha.php"&gt;
          &lt;input type="text" name="captcha" id="captcha" size=10 
                       autocomplete="off" required&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt; 
          &lt;input type="submit" name="submit" id="submit" value="SUBMIT"&gt; 
          &lt;/form&gt;
      &lt;/fieldset&gt; 
  </code></pre>
  
  <p> 
  </p>