0

i am getting this error : Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\loginsystem\includes\signup.inc.php on line 18

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

when i take the semicolon away i get this error: Parse error: syntax error, unexpected 'exit' (T_EXIT) in C:\xampp\htdocs\loginsystem\includes\signup.inc.php on line 19

If somone can please help me i would appreciate it.

thanks

  • 1
    Your if statement is all kinds of messed up. `&&`/`||` operators would make a big difference there. And that's just the **first** issue found... – aynber Dec 08 '17 at 17:30
  • Code is full of syntax errors, see my answer below. As @aynber said.. you're also missing the OR or AND operators.. it's really quite a mess. – DDeMartini Dec 08 '17 at 17:41

2 Answers2

0

1) You are missing a ) at the end of if statement.

2) You should be using an operator may be && or || operator. Insert it according to your requirements.

Updated Code:

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


      ...//rest of the code
oreopot
  • 3,392
  • 2
  • 19
  • 28
0

Your code is full of syntax errors in your IF statements.

Change them to this:

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 - you're assignment has a space in the name..

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

SHOULD BE

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

There are probably other syntax errors too...

Good Luck.

DDeMartini
  • 339
  • 1
  • 6