解析错误:语法错误,第95行C:\xampp\htdocs\PMSS\login.php中的文件意外结束

解析错误:语法错误,第95行C:\xampp\htdocs\PMSS\login.php中的文件意外结束,php,Php,这是我的Login.php <?php //load and connect to MySQL database stuff require("config.inc.php"); if (!empty($_POST)) { if(empty($_POST['username']) || empty($_POST['password'])) { $response["success"] = 0; $response["message"] = "

这是我的Login.php

<?php

//load and connect to MySQL database stuff
require("config.inc.php");

if (!empty($_POST)) {

    if(empty($_POST['username']) || empty($_POST['password'])) {

        $response["success"] = 0;
        $response["message"] = "Please fill in the login details!";
        die(json_encode($response));
    }

    $query = "SELECT  email, password, position FROM user   WHERE   email = :email ";

    $query_params = array(':email' => $_POST['username'],);

    try {
        $stmt   = $db->prepare($query);
        $result = $stmt->execute($query_params);
    }
    catch (PDOException $ex) {
    // For testing, you could use a die and message. 
    //die("Failed to run query: " . $ex->getMessage());

    //or just use this use this one to product JSON data:
        $response["success"] = 0;
        $response["message"] = "Database Error1. Please Try Again!";
        die(json_encode($response));

    }

    //This will be the variable to determine whether or not the user's information is correct.
    //we initialize it as false.
    $validated_info = false;
    $login_ok = false;

    //fetching all the rows from the query
    $row = $stmt->fetch();
    if ($row) {
        //if we encrypted the password, we would unencrypt it here, but in our case we just
        //compare the two passwords
        if ($_POST['password'] === $row['password']) {
            $login_ok = true;       
        }

    // If the user logged in successfully, then we send them to the private members-only page 
    // Otherwise, we display a login failed message and show the login form again 
        if ($login_ok) {
            $response["success"] = 1;
            $response["message"] = "Login Successful!";
            $response["posts"]   = array();

                foreach ($row as $rerow) {
                $row = array(
                $post["position"] = $rerow["position"]
                            );

                array_push($response["posts"], $post);
                }

                die(json_encode($response));
        } 
        else {
            $response["success"] = 0;
            $response["message"] = "Invalid Credentials!";
            die(json_encode($response));
        }

    } 
}   
else {
    ?>
    <h1>Login</h1> 
    <form action="login.php" method="post"> 
        Username:<br /> 
        <input type="text" name="username" placeholder="username" /> 
        <br /><br /> 
        Password:<br /> 
        <input type="password" name="password" placeholder="password" value="" /> 
        <br /><br /> 
        <input type="submit" value="Login" /> 
    </form> 
    <a href="register.php">Register</a>
    <?php
}
?> 

如果可以的话,我想告诉你,你的代码有点乱。记住,压痕可以救你的命


无论如何,我已经看到,如果删除代码的第五行,则不会发现任何错误:

if (!empty($_POST)) {
这里没有关门
if($row){
在登录标题上方的
else
之前关闭。事实上,如果数据库没有返回任何结果,它将显示登录页面


无论如何,第五行是不必要的,因为就在它下面,您可以对特定变量进行控制。您不必检查完整的
$\u POST
数组。

缺少
if(!empty($\u POST)){

if(!empty($\u POST)){
//代码。。。
}否则{
?>
登录
用户名:


密码:



这就是为什么缩进代码非常非常有用的原因。值得学习如何正确缩进代码,以便您能够辨别。如果没有任何嵌套逻辑的指示(即缩进),外人几乎不可能理解您的意图。您在哪里关闭
if(!empty($\u POST)){
?这个问题似乎离题了,因为它缺少一个括号。@尼克:不要在记事本中写代码。找一个真正的编辑器。如果(!empty($_POST)){
我需要使用
如果(!empty($_POST)){
事实上我会将我的android数据传输到php脚本,表单实际上不是needed@Nick:好的,那么……关上它!
    if (!empty($_POST)) {


     //code...

    } else {
    ?>
      <h1>Login</h1>
      <form action="login.php" method="post">
          Username:<br />
          <input type="text" name="username" placeholder="username" />
          <br /><br />
           Password:<br />
           <input type="password" name="password" placeholder="password" value="" />
           <br /><br />
           <input type="submit" value="Login" />
       </form>
      <a href="register.php">Register</a>
    <?php
    }
} // <---- this is missing