Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\PMSS\login.php on line 95

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\PMSS\login.php on line 95

  1. Blog
  2. 15 November 2026
  3. 1 min read

Stefan Bogdanescu

Founder & Senior Architect

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\PMSS\login.php on line 95

The error message Parse error: syntax error, unexpected end of file is one of the most common PHP mistakes. It indicates that the parser reached the very end of the script (EOF) while still expecting more code to complete a statement. In your specific case, the error points to line 95, but the actual culprit is almost certainly located earlier in the file where an opening brace { or tag <?php was never closed.

Looking closely at the provided code for login.php, the issue lies within the logic block that handles a successful login versus a failed one. Specifically, there is a missing closing brace } before the HTML output section begins.

Here is the breakdown of the structural failure in your script:

    if ($login_ok) {
        $response["success"] = 1;
        // ... logic ...
        die(json_encode($response));
    } 
else { // <--- This 'else' belongs to the outer 'if (!empty($_POST))' check, 
        // but inside that block, we have nested conditions.
    
    if ($login_ok) {
        // Success block
        die(json_encode($response));
    } 
    else {
        // Failure block
        $response["success"] = 0;
        $response["message"] = "Invalid Credentials!";
        die(json_encode($response));
    }

} 
// ^--- This closing brace closes the 'else' of the POST check? No.

The code structure around lines 75–95 is malformed. You have an if ($login_ok) block followed by an else block. However, looking at the indentation and the logic flow:

  1. The script initializes $validated_info = false; and $login_ok = false;.
  2. It checks if a row was fetched (if ($row)).
  3. Inside that check, it sets $login_ok = true if passwords match.
  4. The Problem: After the if ($row) block closes, there is no code to handle the case where $row is empty (user not found). The script immediately jumps into an if ($login_ok) check. Since $login_ok is false by default and never set to true if no row exists or if passwords don't match, it will always go to the else block.

However, the syntax error occurs because of how the braces are nested relative to the else statement that outputs the HTML form.

In your code, after the logic for checking credentials finishes (around line 90), there is a closing brace }. Immediately following that is another else. This implies:

    } 
} // Line 89 roughly?
else { // Line 90 roughly?
    ?&gt;
    &lt;h1&gt;Login&lt;/h1&gt; 
    // ... HTML ...
    &lt;?php
} // Line 95?

The parser expects the if ($login_ok) block to be closed, then the outer if (!empty($_POST)) block to be closed. Instead, you have an else statement appearing at the wrong indentation level or without a corresponding opening if.

Specifically, look at this section of your code:

    if ($login_ok) {
        // Success logic
        die(json_encode($response));
    } 
    else {
        // Failure logic
        $response["success"] = 0;
        $response["message"] = "Invalid Credentials!";
        die(json_encode($response));
    }

} 
else {
    ?&gt;
    &lt;h1&gt;Login&lt;/h1&gt; 

There is an extra closing brace } before the final else. The structure suggests you might have closed the if ($row) block, then closed the main logic, and then started a new else that doesn't match any open if.

The Fix:

You need to ensure that the logic determining login success handles the "user not found" scenario explicitly. Currently, if $row is empty, $login_ok remains false. The code then enters the else { Invalid Credentials } block. While this gives a misleading error message ("Invalid Credentials" instead of "User not found"), it runs logically.

However, the syntax error is caused by the mismatched braces surrounding the HTML output section. The correct structure should look like this:

    // ... query execution ...
    
    if ($row) {
        if ($_POST['password'] === $row['password']) {
            $login_ok = true;       
        }
    }

    if ($login_ok) {
        // Success response
        die(json_encode($response));
    } else {
        // Failure response (covers both wrong password and user not found)
        $response["success"] = 0;
        $response["message"] = "Invalid Credentials!";
        die(json_encode($response));
    }

    // Only reach this point if $_POST is empty
} else {
    ?&gt;
    &lt;h1&gt;Login&lt;/h1&gt; 
    // ... HTML Form ...
    &lt;?php
}

By consolidating the conditionals, you remove the nested if/else block that was causing the parser to lose track of where the previous blocks ended. The key is ensuring that every if has exactly one corresponding else (optional but helpful for clarity) and that all braces are balanced before the final else that handles the GET request (the login form).

A Note on Security and Logic

While fixing the syntax error, you should address two critical issues in this code:

  1. Password Comparison: You are comparing passwords using ===. If you hash your passwords (which you absolutely should), you must use password_verify($_POST['password'], $row['password']) instead of a direct string comparison. Storing plain-text passwords or using weak hashing algorithms is a severe security vulnerability.
  2. SQL Injection Risk: Although you are using prepared statements ($stmt = $db->prepare($query)), you are binding the email to :email. Ensure that the database driver treats this as a string and not an integer, which it usually does automatically, but verify your config file handles PDO correctly.

Conclusion

The "unexpected end of file" error is not about the Android app or data retrieval logic; it is purely a PHP syntax issue. The parser hit the end of the script while waiting for a closing brace that was omitted due to incorrect nesting in the if/else block handling the login result. Correcting the brace structure will resolve the fatal error and allow the script to execute, though you should still refactor the logic to distinguish between "user not found" and "wrong password" for better user feedback.

Our network