Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8458157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:00:13+00:00 2026-06-10T13:00:13+00:00

Parse error: syntax error, unexpected T_ELSE <?php require_once(‘config.php’); //error_reporting(0); if (isset($_POST[‘submitted’])) { $username =$_POST[‘username’];

  • 0

Parse error: syntax error, unexpected T_ELSE

<?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->prepare("SELECT username FROM table WHERE username = ?")) {
                $stmt->bind_param('s', $username);
                $stmt->execute();
                $stmt->store_result();

                // Check if the username is in table
                if ($stmt->num_rows > 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('<p class="error">You are not authorized to view this application.</p><div class="clear"></div>');
            } else {
                    // SQL syntax error
                    printf("Prep statment failed: %s\n", $mysqli->error);
        } else {
                    // Invalid LDAP user/pass
                    echo('<p class="error">Invalid username or password.</p><div class="clear"></div>');
                }
            }
        }
    }
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:00:14+00:00Added an answer on June 10, 2026 at 1:00 pm

    You should be more careful with your brackets. Try this:

    <?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->prepare("SELECT username FROM table WHERE username = ?")) {
                $stmt->bind_param('s', $username);
                $stmt->execute();
                $stmt->store_result();
    
                // Check if the username is in table
                if ($stmt->num_rows > 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('<p class="error">You are not authorized to view this application.</p><div class="clear"></div>');
                }
            } else {
                // SQL syntax error
                printf("Prep statment failed: %s\n", $mysqli->error);
            }
        } else {
            // Invalid LDAP user/pass
            echo('<p class="error">Invalid username or password.</p><div class="clear"></div>');
        }
    }
    ?>
    

    PROTIP: To avoid this in the future, write your brackets first, then put your code inside the brackets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm getting this error: Parse error: syntax error, unexpected T_PRINT, expecting T_STRING in /homepages/26/d94605010/htdocs/lz/writecodeonline.com/php/index.php(190)
I get an error that says Parse error: syntax error, unexpected T_PRIVATE in E:\PortableApps\xampp\htdocs\SN\AC\ACclass.php
This is the error: Parse error: syntax error, unexpected '}' in /home/idghosti/public_html/testground/mma/include/footer.php on line
I am getting this error : Parse error: syntax error, unexpected T_OBJECT_OPERATOR in wp-content/themes/phil/page.php
I keep getting a syntax error Parse error: syntax error, unexpected '{' in contact_form.php
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in ds.php on line
I get this PHP error: Parse error: syntax error, unexpected T_VARIABLE From this line:
I get this error... Parse error: syntax error, unexpected '{', expecting '(' in /home/content/s/k/y/skyview09/html/clients/Cheryl/admin/admin.php
Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION in C:\wamp\www\Exam Creator\cls_FillInTheBlank.php on line 31
Parse error: syntax error, unexpected T_IF in view.php on line 27 I really dont

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.