-4

i've been trying to fix this error past 4 hours now, and i lost my hopes to do it on my own, so i've getting this error:

Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in D:\xampp\htdocs\Login system\includes\signup.inc.php on line 13

How to get it fixed? I overlooked everywhere cuz i knew somewhere could be some left unclosed brackets.

And heres my php code, HELP ALLERT :<

<?php

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

    include_once 'dbh.inc.php';

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

    //Error Handlers
    //check for empty fields
    if (empty($uid) || empty(email) || empty($pwd)) {
        header("Location:  ../signup.php?signup=empty");
        exit();
    } else {
        //Check if input characters are valid
        if (!preg_match("/^[a-zA-Z*$/]", $uid)) {
            header("Location:  ../signup.php?signup=empty");
            exit();
        } else {
        //Check if email is valid
        if (!filter_var($email, FILTER_VALIDATE_EMAIL))
            header("Location:  ../signup.php?signup=empty");
            exit();
        } else {

            $sql = "SELECT * FROM users WHERE user_uid='$uid'";
            $result = mysql_query($conn, $sql);
            $resultCheck = mysqli_num_rows($result);

            if($resultCheck > 0) {
                header("Location:  ../signup.php?signup=usertaken");
                exit();
            } else {
                //Haching the password
                $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
                //Insert the user into the database
                $sql = "INSERT INTO users (user_email, user_uid, user_pwd) 
                        VALUES ('$uid', '$email', '$hashedPwd' );";
                $result = mysqli_query($conn, $sql);
                header("Location:  ../signup.php?signup=success");
                exit();
            }
        }
    }
} else {
    header("Location:  ../signup.php");
    exit();
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • To make everything clear guys - This is my first PHP code on my own. – Matas Žemaitis Jul 21 '18 at 10:45
  • Check some syntax error like `empty(email)` – Niklesh Raut Jul 21 '18 at 10:48
  • 2
    You are missing the `$` in front of email in the `empty(email)` check. – Dave Jul 21 '18 at 10:48
  • Some sensible code indentation would be a good idea. It helps us read the code and more importantly it will help **you debug your code** [Take a quick look at a coding standard](http://www.php-fig.org/psr/psr-2/) for your own benefit. You may be asked to amend this code in a few weeks/months and you will thank me in the end. – RiggsFolly Jul 21 '18 at 14:46

1 Answers1

-2

You're writing the if-else statements the wrong way, the error you're getting is from the if statement with no opening and closing curly brackets, same goes for the other ones. try this one:

    <?php
    include_once 'dbh.inc.php';
    if (!isset($_POST['submit'])) {
        header("Location:  ../signup.php");
        exit();
    }
    $uid = mysqli_real_escape_string($conn, $_POST['uid']);
    $pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
    $email = mysqli_real_escape_string($conn, $_POST['email']);

    //Error Handlers
    //check for empty fields
    if (empty($uid) || empty(email) || empty($pwd)) {
        header("Location:  ../signup.php?signup=empty");
        exit();
    }

    if (!preg_match("/^[a-zA-Z*$/]", $uid)) {
        header("Location:  ../signup.php?signup=empty");
        exit();
    }

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
        header("Location:  ../signup.php?signup=empty");
        exit();
    }


    if($resultCheck > 0) {
        header("Location:  ../signup.php?signup=usertaken");
        exit();
    }

    $sql = "SELECT * FROM users WHERE user_uid='$uid'";
    $result = mysql_query($conn, $sql);
    $resultCheck = mysqli_num_rows($result);

    if($resultCheck > 0) {
        header("Location:  ../signup.php?signup=usertaken");
        exit();
    }

    //Haching the password
    $hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
    //Insert the user into the database
    $sql = "INSERT INTO users (user_email, user_uid, user_pwd) VALUES ('$uid', '$email', '$hashedPwd' );";
    $result = mysqli_query($conn, $sql);
    header("Location:  ../signup.php?signup=success");
    exit();
Fadi Obaji
  • 1,454
  • 4
  • 27
  • 57
  • @james yes their are missing brackets, take a look at the code and if you get confused, just copy and paste the code in your IDE, i don't get how your rep is 3425! ha – Fadi Obaji Jul 21 '18 at 11:20
  • 1
    Yeah, the Fadi is right, it fixed my problem, and Dave was right too, i was missing "$" in front of email, but now i get one more problem... "Object not found" – Matas Žemaitis Jul 21 '18 at 11:25
  • So I started looking at the braces and they look fine, but given the fact the missing braces are way down the code it would have been useful (necessary really) to explain this in your answer. Rather than just dump the OPs large amount of code and state "fixed it was some braces" and expect people to try to find where you fixed it, especially as it's not on "line 13" as per the error ;) – James Jul 21 '18 at 11:25
  • @MatasŽemaitis update your question – Fadi Obaji Jul 21 '18 at 11:27
  • Okay James, sorry, i'm new here don't know everything yet.:) – Matas Žemaitis Jul 21 '18 at 11:32
  • How to close the question? :| – Matas Žemaitis Jul 21 '18 at 11:33
  • @MatasŽemaitis It's fine to ask your question :) just turned out to be a simple typo is all. A suggestion though, you should get an IDE (code editor) which has syntax highlighting, it shows you right there any issues, such as "*undefined constant email*" would have been highlighted and the missing braces etc. Saves you a lot of time :) – James Jul 21 '18 at 11:33
  • @James We normally close and delete TYPO's They rarely if ever are any use to others. – RiggsFolly Jul 21 '18 at 14:50