title: PHP Error: First Word Press Custom Registration Page - There has been a critical error on your website
body: <p>This is my first PHP based word press forum I'm trying to build. I'm following an Online tut but I'm getting and error. I know .Net fairly well but PHP is new to me. I've never seen this error before and I'm not sure what my error is currently</p>
  
  <p>Error message:</p>
  
  <blockquote>
    <p>There has been a critical error on your website.Learn more about
    debugging in WordPress.</p>
  </blockquote>
  
  <p>I have tried enabling debug mode. Likely I did something wrong. </p>
  
  <p>PHP Code:</p>
  
  <pre><code>&lt;?php
  /* Template Name: WBG Registration */
  global $wpdb;
  
  if($_POST)
  {
      $username = $wpdb-&gt;escape($_POST['txtUserName']);
      $email = $wpdb-&gt;escape($_POST['txtEmail']);
      $password = $wpdb-&gt;escape($_POST['txtPassword']);
      $confirmpassword = $wpdb-&gt;escape($_POST['txtConfirmPassword']);
      $recoveryquestion = $wpdb-&gt;escape($_POST['txtRecoveryQuestion']);
      $recoveryanswer = $wpdb-&gt;escape($_POST['txtRecoveryAnswer']);
      $error = array();
  
      if(strpos($username, ' ') !==FALSE)
      {
          $error['username_space'] = "Chat Handle can not contain spaces";
      }
  
      if(empty($username))
      {
          $error['username_empty'] = "Chat Handle required field";
      }
  
      if(username_exist($username))
      {
          $error['username_existt'] = "Chat Handle already exists";
      }
  
      if(!is_email($email))
      {
          $error['email_invalid'] = "Invalid Emaill Address";
      }
  
      if(email_exist($email))
      {
          $error['email_exist'] = "Email already being used";
      }
  
      if(empty($password))
      {
          $error['password_empty'] = "Password is required field";
      }
  
  
      if(count($error) == 0)
      {
          wp_create_user($username, $password, $email);
          echo "User Created";
          header("Location: http://www.whiteboxgaming.com");
          exit();
      }   
      else
      {
          print_r($error);
          header("Location: http://www.whiteboxgaming.com/registration");
      }   
  }
  </code></pre>
  
  <p>?></p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div style="width: 100%;"&gt;
  &lt;div style="width: 100%;background-color:#5BCBBC;"&gt;
      &lt;!-- Banner --&gt;
          &lt;img src="https://whiteboxgaming.com/wp-content/uploads/2020/03/cropped-Header_WBG-3.png" alt="White Box Gaming Banner"&gt;
  &lt;/div&gt;
  &lt;div style="width:100%;background-color:#FFFFFF; font-size:40px; color:#C2C2C2;" align="left"&gt;
      &lt;br&gt;&lt;label&gt;Registration&lt;/label&gt;&lt;br&gt;&lt;br&gt;
      &lt;form method="post"&gt;
          &lt;div style="width: 100%;border: padding:60px; font-size:40px; color:#C2C2C2;" align="center"&gt;
              &lt;div style="width: 100%; padding:25px;"&gt;
                  &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt;  
                      &lt;label&gt;Email&lt;/label&gt;&lt;br&gt;
                      &lt;input type="text" name="txtEmail" id="txtEmail" placeholder="Email Address" style="font-size:20px; width: 90%;"/&gt;
                  &lt;/div&gt;                              
                  &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt; 
                      &lt;label&gt;Password&lt;/label&gt;&lt;br&gt;
                      &lt;input type="password" name="txtPassword" id="txtPassword" placeholder="Enter Password" style="font-size:20px; width: 90%;"/&gt;
                  &lt;/div&gt;
                  &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt; 
                      &lt;label&gt;Chat Handle&lt;/label&gt;&lt;br&gt;
                      &lt;input type="text" name="txtUserName" id="txtUserName" placeholder="User Name" style="font-size:20px; width: 90%;"/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div style="width: 100%; padding:25px;"&gt;
                  &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt; 
                      &lt;label&gt;Recovery Question&lt;/label&gt;&lt;br&gt;
                      &lt;input type="text" name="txtRecoveryQuestion" id="txtRecoveryQuestion" placeholder="Recovery Question" style="font-size:20px; width: 90%;"/&gt;
                  &lt;/div&gt;
                  &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt;  
                      &lt;label&gt;Recovery Answer&lt;/label&gt;&lt;br&gt;
                      &lt;input type="text" name="txtRecoveryAnswer" id="txtResoveryAnswer" placeholder="Recovery Answer" style="font-size:20px; width: 90%;"/&gt;
                  &lt;/div&gt;
                  &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div style="width: 100%; padding:25px;"&gt;
              &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt;
                  &lt;!--&lt;input type="submit" src="https://drive.google.com/uc?export=view&amp;id=1OHKkPxRJgNZfORfVvUOOO4lMeeaTlthc" alt="Submit" width="100%" value="Create Account"&gt;--&gt;
                  &lt;input type="image" src="https://drive.google.com/thumbnail?id=1W91IDBPLuVIRgk9lX_uGHkIWzJUhnE9l" alt="Create account" /&gt;
              &lt;/div&gt;
              &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt;&lt;/div&gt;
              &lt;div style="width: 30%; height: 100px; float: left;" align="left"&gt;&lt;/div&gt;                
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>Not the best code but just following the Tut and trying to adapt it to my needs. What I'm expecting is to print out every thing in my array when error occurs else create a account in my Word Press database. Any help or video tuts would be great. I'm newb to word press and PHP. I'd like to get this fixed.  </p>
  
  <p>Update:
  I have narrowed it down to these two functions I commented out in my code:</p>
  
  <pre><code>&lt;?php
  /* Template Name: WBG Registration */
  global $wpdb;
  
  if($_POST)
  {
      $username = $wpdb-&gt;escape($_POST['txtUserName']);
      $email = $wpdb-&gt;escape($_POST['txtEmail']);
      $password = $wpdb-&gt;escape($_POST['txtPassword']);
      $confirmpassword = $wpdb-&gt;escape($_POST['txtConfirmPassword']);
      $recoveryquestion = $wpdb-&gt;escape($_POST['txtRecoveryQuestion']);
      $recoveryanswer = $wpdb-&gt;escape($_POST['txtRecoveryAnswer']);
      $error = array();
  
  
      if(strpos($username, ' ') !==FALSE)
      {
          $error['username_space'] = "Chat Handle can not contain spaces";
      }
  
      if(empty($username))
      {
          $error['username_empty'] = "Chat Handle required field";
      }
  
      /*
      if(username_exist($username))
      {
          $error['username_existt'] = "Chat Handle already exists";
      }*/
  
      if(!is_email($email))
      {
          $error['email_invalid'] = "Invalid Emaill Address";
      }
  
      /*
      if(email_exist($email))
      {
          $error['email_exist'] = "Email already being used";
      }*/
  
      if(empty($password))
      {
          $error['password_empty'] = "Password is required field";
      }
  
      if(count($error) == 0)
      {
          wp_create_user($username, $password, $email);
          header("Location: http://www.whiteboxgaming.com");
          exit();
      }   
      else
      {
          print_r($error);
          header("Location: http://www.whiteboxgaming.com/registration");
      }
  }
  </code></pre>
  
  <p>?></p>
  
  <p>I'm not sure how WordPress validates if a user name or email already exist. Is there a PHP function I can use? </p>