title: How to display message when a user submits the form
body: <p>Hi I have the following code. I was just wondering how to add a message/popup to say "thanks for registering" if everything is successful. Here is the code and btw i am new the php. Thanks for your help</p>
  
  <pre><code>&lt;?php 
  require("config.php");
  if(!empty($_POST)) 
  { 
      // Ensure that the user fills out fields 
      if(empty($_POST['username'])) 
      { die("Please enter a username."); } 
      if(empty($_POST['password'])) 
      { die("Please enter a password."); } 
      if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) 
      { die("Invalid E-Mail Address"); } 
  
      // Check if the username is already taken
      $query = " 
          SELECT 
              1 
          FROM users 
          WHERE 
              username = :username 
      "; 
      $query_params = array( ':username' =&gt; $_POST['username'] ); 
      try { 
          $stmt = $db-&gt;prepare($query); 
          $result = $stmt-&gt;execute($query_params); 
      } 
      catch(PDOException $ex){ die("Failed to run query: " . $ex-&gt;getMessage()); } 
      $row = $stmt-&gt;fetch(); 
      if($row){ die("This username is already in use"); } 
      $query = " 
          SELECT 
              1 
          FROM users 
          WHERE 
              email = :email 
      "; 
      $query_params = array( 
          ':email' =&gt; $_POST['email'] 
      ); 
      try { 
          $stmt = $db-&gt;prepare($query); 
          $result = $stmt-&gt;execute($query_params); 
      } 
      catch(PDOException $ex){ die("Failed to run query: " . $ex-&gt;getMessage());} 
      $row = $stmt-&gt;fetch(); 
      if($row){ die("This email address is already registered"); } 
  
      // Add row to database 
      $query = " 
          INSERT INTO users ( 
              username, 
              password, 
              salt, 
              email 
          ) VALUES ( 
              :username, 
              :password, 
              :salt, 
              :email 
          ) 
      "; 
  
  
      // Security measures
      $salt = dechex(mt_rand(0, 2147483647)) . dechex(mt_rand(0, 2147483647)); 
      $password = hash('sha256', $_POST['password'] . $salt); 
      for($round = 0; $round &lt; 65536; $round++){ $password = hash('sha256', $password . $salt); } 
      $query_params = array( 
          ':username' =&gt; $_POST['username'], 
          ':password' =&gt; $password, 
          ':salt' =&gt; $salt, 
          ':email' =&gt; $_POST['email'] 
      ); 
      try {  
          $stmt = $db-&gt;prepare($query); 
          $result = $stmt-&gt;execute($query_params); 
      } 
      catch(PDOException $ex){ die("Failed to run query: " . $ex-&gt;getMessage()); } 
      header("Location: index.php"); 
  
      die("Redirecting to index.php"); 
  
  
  } 
  </code></pre>
  
  <p>?></p>