我得到一个看起来像这样的错误:解析错误:语法错误,意外&#39 ;;'在第18行

时间:2017-12-08 17:25:59

标签: php

我收到此错误: 解析错误:语法错误,意外&#39 ;;'在第18行的C:\ xampp \ htdocs \ loginsystem \ includes \ signup.inc.php

        <?php

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

        include_once 'dbh.inc.php';

        $first = mysqli_real_escape_string($conn, $_POST['first']);
        $last = mysqli_real_escape_string($conn, $_POST['last']);
        $email = mysqli_real_escape_string($conn, $_POST['email']);
        $uid = mysqli_real_escape_string($conn, $_POST['uid']);
        $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);

        //error handlers
        // check for empty fields

        if (empty($first)) (empty($last)) (empty($email)) (empty($uid)) (empty($pwd)) {

            header ("location: ../signup.php?signup=empty");
            exit();

        } else {
            //check if input characters are valid
            if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last) {

                header("location: ../signup.php?signup=invalid");
                exit();

            } else {
            // check if eimal is valid
                if (!filter_var($email, FILTER_VALIDATE_EMAIL))

                    header("location: ../signup.php?Signup=email");
                    exit();
            } else {
                $sql = "SELECT * FROM users WHERE user_uid='$uid'";
                $result = mysqli_query($conn, $sql);
                $resultCheck = mysqli_num_rows($result);

                if ($resultCheck > 0) {

                    header("location: ../signup.php?signup=usernametaken");
                    exit();
                } else {
                    //Hashing th password
                    $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);

                    //Insert the user into the database
                    $sq l= "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES ('$first', '$last', '$emial', '$uid','$hashedPwd');";

                    mysqli_query($conn, $sql);
                    header("location: ../signup.php?signup=success");
                    exit();
                }
            }
        }

    }   else {
        header("location: ../signup.php");
        exit();

当我拿走分号时我得到了这个错误: 解析错误:语法错误,意外退出&#39;第19行的C:\ xampp \ htdocs \ loginsystem \ includes \ signup.inc.php中的(T_EXIT)

如果somone能帮助我,我会很感激。

感谢

2 个答案:

答案 0 :(得分:0)

1)您在)声明结尾处遗漏了if

2)您应该使用运营商可能是&&||运营商。根据您的要求插入。

更新代码:

if (empty($first)) && (empty($last)) && (empty($email)) && (empty($uid)) && (empty($pwd))) {


      ...//rest of the code

答案 1 :(得分:0)

您的代码在您的IF语句中充满了语法错误。

将它们更改为:

if ((empty($first))  (empty($last))  (empty($email))  (empty($uid))  (empty($pwd))) {

AND

if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {

AND

 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {

AND HERE - 你的任命在名字中有一个空格..

 $sq l= "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES ('$first', '$last', '$emial', '$uid','$hashedPwd');";

应该

$sql = "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES ('$first', '$last', '$emial', '$uid','$hashedPwd');";

也可能存在其他语法错误......

祝你好运。