解析错误语法;意外的文件结尾

时间:2017-03-17 15:21:37

标签: php parsing

所以我第一次编写PHP,我为潜在的网站创建了一个注册页面。但是当我去运行代码时,它给了我以下内容:

解析错误:语法错误,第123行的C:\ LOCATION中意外的文件结尾

我知道我很可能在某个地方错过了一个大括号。但对于我的生活,我无法找到它。如果有人可以看一眼他们的眼睛并发现它我会很感激:)

<?php
$page_title = 'Register';
include 'header.php';

//master control to ensure scripts only execute when form is submitted
if ($_SERVER['REQUEST_METHOD']=='POST')
{
    //Opens connection to database and create an array to store any errors in
    require 'connect.php';
    $errors = array();

    //Checks to see if username is empty and if not true stores it into a variable
    if( empty($_POST['username']))
    {
        $errors[] = 'Please enter username';
    }
    else
    {
        $username = mysqli_real_escape_string($conn,trim($_POST['username']));
    }

    //Checks to see if email is empty and if not true stores it into a varible
    if( empty($_POST['email']))
    {
        $errors[] = 'Please enter email';
    }
    else
    {
        $email = mysqli_real_escape_string($conn,trim($_POST['email']));
    }

    //Check to see if passwords match and if they do store into variable
    if( !empty($_POST['pass1']))
    {
        if( $POST['pass1'] != $_POST['pass2'])
        {
            $errors[] = 'Passwords do not match';
        }
        else
        {
            $pass = mysqli_real_escape_string($conn, trim($_POST['pass1']));
        }
    }
    else
    {
        $errors[] = 'Please enter a password';
    }

    //Checks to see if Email is already registered
    if( empty( $errors))
    {
        $q = "SELECT user_id FROM users WHERE user_email='$email'";
        $r = mysqli_query($conn, $q);
        if( mysqli_num_rows($r) != 0)
        {
            $errors[] = 'Email Address is already registered';
        }

    //Checks to see if username is already taken
    if( empty( $errors))
    {
        $q = "SELECT user_id FROM users WHERE user_name='$username'";
        $r = mysqli_query($conn, $q);
        if( mysqli_num_rows($r) != 0)
        {
            $errors[] = 'Username is already taken, please choose another';
        }

    //If successful send data to to database
    if( empty( $errors))
    {
        $q = "INSERT INTO users
            (user_name, user_pass, user_email, user_date, user_level)
            VALUES ('$username', SHA1('$pass'), '$email', NOW(), '0')";
        $r = mysqli_query($conn, $q);

        if($r)
        {
            echo'<h1>Registered!</h1>
                <p>you may now login</p>';
        }

            //Closes connections
            mysqli_close($conn);
            include 'footer.php';
            exit();
    }
    //Otherwise display errors
    else
    {
        echo'<h1>Error!</h1>
            <p>Following errors have occured:<br>';
        foreach($errors as $msg)
        {
            echo " - $msg<br>";
        }
        echo '<p>Please try again</p>';
        mysqli_close($conn);
    }

}
?>

<h1>Sign-up</h1>
<form action="signup.php" method="POST">
    <p>
        Username:<input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username'];?>">
    </p>
    <p>
        Password:<input type="password" name="pass1">
        Repeat Password:<input type="password" name="pass2">
    </p>
    <p>
        E-Mail Address:<input type="text" name="email" value="<?php if (isset($_POST['email'])) echo $_POST['email'];?>">
    </p>
    <p>
    <input type="submit" value="register">
    </p>
</form>

<?php
    include'footer.php';
?>

0 个答案:

没有答案
相关问题