PHP中出现意外错误

时间:2017-11-27 05:16:59

标签: php

我收到以下错误。我检查了Stack Overflow帖子的情况,但我无法弄明白,我真的在代码里面看了大约30分钟。对于能帮我解决这个错误的人,我真的很感激。我认为我的括号完全搞砸了...... 错误是:

  

解析错误:语法错误,意外'{'in       第20行的C:\ xampp \ htdocs \ photographer \ includes \ signup.inc.php

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 handler
//checking for empty fields
if(empty($first) || empty($last) || empty($email) || empty($uid) ||         
empty($pwd) ) {
    header("Location: register.php?register=empty");
    exit();

}   else {
    //check if input characters are valid 
 if(!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", 
$last) {
    header("Location: register.php?register=invalid");
    exit();
}       else {
            //check if e-mail is valid
        if (filter_var($email,FILTER_VALIDATE_EMAIL)) {
            header("Location: register.php?register=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: register.php?register=usertaken");
                exit();

            } else {
                // hashing pass
                $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
                //insert the user in db 
                $sql = "INSERT INTO users (user_first, user_last, 
  user_email, user_uid, user_pwd) VALUES ('$first', '$last', '$email', 
 '$uid', '$hashedPwd');";
                mysqli_query($conn, $sql);
                header ("Location: register.php?register=succes");
                exit();

            }


        }


        }

    }



else {
header("Location: register.php");
exit();


}

?>

提前感谢任何可能回答我问题的人!

2 个答案:

答案 0 :(得分:1)

尝试使用以下格式重写您的else-if语句:

if ($a < "1") {
    echo "";
} elseif ($a < ">1") {
echo "Hello world!";
}

所以你有以下的东西:

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

使用elseif重写它们。

示例:https://www.w3schools.com/php/php_if_else.asp

答案 1 :(得分:0)

你错过了一个&#39; {&#39;和&#39;);变化:

添加&#39;)&#39;在@manassehkatz

讲述的if块的末尾
if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {

并添加另一个&#39;}&#39;

之前
else {
header("Location: register.php");
exit();
}

必须有5&#39;}&#39;在上面给出之前关闭所有括号,你只有4&#39;}&#39;。