title: Parse error: syntax error, unexpected T_CATCH in... on line 65?
body: <p>The error occurs on line 65: } catch (Exception $e){</p>
  
  <pre><code>&lt;?php
  
  require "includes/connect.php";
  
  
  
  function generateCode($length = 5)
  {
      $characters = 'bcdfghjkmnpqrstvwxyz';
      $string = '';
  
      for ($i = 0; $i &lt; $length; $i++) {
          $string .= $characters[rand(0, strlen($characters) - 1)];
      }
      return $string;
  }
  
  
  $msg = '';
  
  
  if($_POST['email']) {
  
      // Requested with AJAX:
      $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH']  == 'XMLHttpRequest');
  
  
      try {
  
          if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
              throw new Exception('Invalid Email!');
          }
  
          if($ajax){
              die('{"status":1}');
          }
  
          $unique_code = "";
          $inserted = false;
  
          // Keep looping until we've inserted a record
          while(!$inserted) {
  
              // Generate a code
              $unique_code = generateCode();
  
              // Check if it exists
              if ($result = $mysqli-&gt;query("SELECT unique_code FROM coming_soon_emails WHERE unique_code = '$unique_code'")) {
  
              // Check no record exists
              if ($result-&gt;num_rows == 0) {
  
                  // Create new record
                  $mysqli-&gt;query("INSERT INTO coming_soon_emails (email,unique_code) VALUES ('" . $mysqli-&gt;real_escape_string($_POST['email']) . "','$unique_code')");
  
                  // Set inserted to true to ext loop
                  $inserted = true;
  
                  // Close the result object
                  $result-&gt;close();
              }
          }
  
      } catch (Exception $e){
  
          if($ajax){
              die(json_encode(array('error'=&gt;$e-&gt;getMessage())));
          }
  
          $msg = $e-&gt;getMessage();
          die($msg);
      }      
  
  } else {
      // Quit if we can't check the database
      die('Something went wrong with select');
  }   
  
  
  
  ?&gt;
  </code></pre>