Cant find the error in my code

I am trying to do a login on my website, i have written some code but when i run it i get this error:

    Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\Blog website\includes\signup_inc.php on line 21

Here is line 21…

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

Here is the else function:

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

Here is all of the code…

<?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 email 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=email");
            exit();                 
            } else {
                //Hashing the password
                $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
                //Insert the user into the database
                $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: ../signup.php?signup=success");
                exit();
            }
        }
    }
}

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

I cant find the error, i have gone through the code million of times now.

I have found the error, consider this closed.

Missing a closing bracket on the previous line?

Glad you got it working.

Just let me throw in the obligatory “use prepared statements” security warning.

And if an if clause exits then there is really no need for an else. Just makes the code harder to follow.

if ($something) {
    echo "Oh No Mr Bill";
    exit();
}
// And continue

Dosnt continue much after that :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.