title: PHP User Registration Page
body: <p>I built a new registration page for a php app. Ths processes the user registration page. After user has submitted user information, it doesnt redirect to "index.php" but rather to a blank page. PLease</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
      
      require 'database-config.php';
      
      session_start();
  
         $username = $_POST['username'];
         $password = $_POST['password'];
         $password = md5($password);
         $user_access_level = $_POST['radios'];
         $dt = date('d-m-Y');
         
         $query = $dbh-&gt;prepare("SELECT * FROM users WHERE username=:username");
         $query-&gt;execute(array(':username' =&gt; $username));
  
         if($query != false){
             while($q = $query -&gt; fetch(PDO::FETCH_ASSOC)){
                 $error = '&lt;br&gt;&lt;div class="info"&gt;Sorry, the username &lt;b&gt;'.$username.'&lt;/b&gt; is already in use. Please enter a different username of your choice to proceed. Thanks.&lt;/div&gt;&lt;br&gt;';
             }    
         }
         
         else {
             $insert = $dbh-&gt;prepare('INSERT INTO users(username, password, user_access_level, date) VALUES(:username, :password, :user_access_level, :date)');
             $insert-&gt;execute(array(':username'=&gt;$username,':password'=&gt;$password,':user_access_level'=&gt;$user_access_level,':date'=&gt;$dt));
             
             if(insert!=false){
                 header("location: index.php");
             }
             else{
                 $error = '&lt;br&gt;&lt;div class="info"&gt;Sorry, your account could not be created at the moment. Please try again or contact the site admin to report this error if the problem persist. Thanks.&lt;/div&gt;&lt;br&gt;';
             }
             
         }
     
      
      
  ?&gt;</code></pre>
  </div>
  </div>
  </p>