PHP - 其他意外

时间:2013-01-16 16:44:01

标签: php if-statement

有人能告诉我为什么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>';


            }                               
?>

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

    echo "You have been successfully registered.";

'}'

} else {
    echo "Error registering.";
}

这就是问题所在。我引用的括号。

我强烈建议您使用专为PHP设计的IDE(例如Eclipse PDT)。它会告诉你问题与你的语法有关。