-1

I get the following error. I checked the Stack Overflow post for situations like that but I couldn't figure it out,i really looked inside the code for around 30 minutes. I'd be really thankful for anyone who could help me with this error. I think my brackets are completely messed up... The error is :

Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\photographer\includes\signup.inc.php on line 20

The signup.inc.php file code is :

<?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();


}

?>

Thanks in advance for anyone that might answer my question!

chris85
  • 23,846
  • 7
  • 34
  • 51
GummyGod
  • 11
  • 4

3 Answers3

4

You are missing a ) Change:

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

to:

if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
  • Thanks it worked.Now it generated a new error.. Parse error: syntax error, unexpected 'else' (T_ELSE) in C:\xampp\htdocs\photographer\includes\signup.inc.php on line 59 idk what's happening with ym code tbh – GummyGod Nov 27 '17 at 05:28
  • 1
    Because you're using two else. You can't have if(){}else{}else{} – hungrykoala Nov 27 '17 at 05:32
1

Try rewriting your else-if statements in the following format instead:

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

So where you have things such as:

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

rewrite them using elseif.

Example: https://www.w3schools.com/php/php_if_else.asp

samcozmid
  • 134
  • 9
0

You are missing a and '{' and '); Change:

add ')' at the end of the the if block as told by @manassehkatz

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

and add another one '}' before the

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

There must be 5 '}' before the above given else to close all the bracket and you have only 4 '}'.

Sushank Pokharel
  • 869
  • 7
  • 15