title: PHP nested if/else logic
body: <blockquote>
    <p>Parse error: syntax error, unexpected T_ELSE</p>
  </blockquote>
  
  <pre><code>&lt;?php
      require_once('config.php');
  
      //error_reporting(0);
      if (isset($_POST['submitted'])) {
  
          $username =$_POST['username'];
          $password=$_POST['password'];
  
          $ldap = ldap_connect("localserv1.local.local.edu", 389) or exit("Error connecting to LDAP server.");
  
          //Settings for AD
          ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
          ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
  
          //Check if user can access LDAP
          if ($bind = ldap_bind($ldap, 'local\\'.$username, $password)) {
              //Prep SQL statement
              if ($stmt = $mysqli-&gt;prepare("SELECT username FROM table WHERE username = ?")) {
                  $stmt-&gt;bind_param('s', $username);
                  $stmt-&gt;execute();
                  $stmt-&gt;store_result();
  
                  // Check if the username is in table
                  if ($stmt-&gt;num_rows &gt; 0) {
  
                      // Log them in
                      session_register("username");
                      session_register("password");
                      header("Location: https://" . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, -9) . "index.php" );
                      exit;
  
                  } else {
                      //User is not in table
                      echo('&lt;p class="error"&gt;You are not authorized to view this application.&lt;/p&gt;&lt;div class="clear"&gt;&lt;/div&gt;');
              } else {
                      // SQL syntax error
                      printf("Prep statment failed: %s\n", $mysqli-&gt;error);
          } else {
                      // Invalid LDAP user/pass
                      echo('&lt;p class="error"&gt;Invalid username or password.&lt;/p&gt;&lt;div class="clear"&gt;&lt;/div&gt;');
                  }
              }
          }
      }
  }
  ?&gt;
  </code></pre>