-1

谁能告诉我为什么 PHP 给我这个错误?:

Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\Task2PHP\final\registration.php on line 139

(错误是*中的错误,因为我没有输出所有代码)

我似乎找不到问题

代码:

<?php

if ($isLoggedin === false) {

                                include("form.php");


                                    if (isset($_POST['Name'])) {

                                        // DECLARE VARIABLES TO NULL
                                        $Name = null; $Surname = null; $Username = null; $Email = null; $C_Email = null; $Password = null; $C_Password = null; $SecQ = null; $SecA = null;

                                        // GET ELEMENTS FROM BROWSER POST.
                                        if (isset($_POST['Name'])) {
                                            $Name = $_POST['Name'];
                                        }
                                        if (isset($_POST['Surname'])) {
                                            $Surname = $_POST['Surname'];
                                        }
                                        if (isset($_POST['Username'])) {
                                            $Username = $_POST['Username'];
                                        }
                                        if (isset($_POST['Email'])) {
                                            $Email = $_POST['Email'];
                                        }
                                        if (isset($_POST['C_Email'])) {
                                            $C_Email = $_POST['C_Email'];
                                        }
                                        if (isset($_POST['password'])) {
                                            $Password = $_POST['password'];
                                        }
                                        if (isset($_POST['c_password'])) {
                                            $C_Password = $_POST['c_password'];
                                        }
                                        if (isset($_POST['SecQ'])) {
                                            $SecQ = $_POST['SecQ'];
                                        }
                                        if (isset($_POST['SecA'])) {
                                            $SecA = $_POST['SecA'];
                                        }

                                        // CONNECT TO MYSQL DB
                                        $con = mysql_connect('localhost', 'storefileuser', 'storefileuser');
                                        mysql_select_db ("storefile");


                                        if (!$con) {

                                                die('Could not connect: ' . mysql_error());
                                            } else {

                                                if ($Name == null || $Surname== null || $Password == null || $C_Password == null || $Email == null || $C_Email == null || $SecQ == null || $SecA == null ) {
                                                    echo "Missing details. Please enter all fields.";
                                                } else {

                                                    $usernameexists = false;
                                                    $emailexists = false;
                                                    $result = mysql_query("SELECT * FROM users WHERE username = '$Username'");
                                                    if (mysql_num_rows($result) > 0) {
                                                        $usernameexists = true;
                                                    }
                                                    $result = mysql_query("SELECT * FROM users WHERE Email = '$Email'");
                                                    if (mysql_num_rows($result) > 0) {
                                                        $emailexists = true;
                                                    }

                                                    if (!$emailexists || !$usernameexists) { 
                                                        // VALIDATE CONFIRMS
                                                        if  ($Email == $C_Email && $Password == $C_Password) {

                                                            $encrypt_password=md5($Password);

                                                            $query = "INSERT INTO users (Username, Name,Surname, Password, Email, SecQ, SecA) VALUES ('".$Username."', '".$Name."', '".$Surname."', '".$encrypt_password."', '".$SecQ."', '".$SecA."', '".$Email."')";


                                                            echo "You have been successfully registered.";


                                                            }

                                                        } else {
                                                            echo "Error registering.";


                                                    } else {
                                                        echo "Username or email already entered in the database!";
                                                    }
                                                }
                                        }

                                    } 






    }   else {

            echo '<h1> You are already registered/logged in!</h1>';


            }                               
?>
4

2 回答 2

2

在你的大 if 语句之前有一个额外的右花括号} else {(你知道我在说哪一个)

和:

139 之前的几行,缺少一个花括号。

    } else {
        echo "Error registering.";
    } // here is where it should be.                            
} else {
    echo "Username or email already entered in the database!";
}

工作代码: http: //pastebin.com/NcL85pnu

于 2013-01-16T16:47:26.360 回答
0
    echo "You have been successfully registered.";

'}'

} else {
    echo "Error registering.";
}

那就是问题所在。我用引号括起来的括号。

我强烈建议您使用为 PHP 设计的 IDE(例如 Eclipse PDT)。它会准确地告诉你问题出在你的语法上。

于 2013-01-16T16:51:28.507 回答