-2

I made a simple sign up system with PHP and phpmyadmin. However, every time I try to enter text into my inputs and press submit, it comes up as a syntax error that says "Parse error: syntax error, unexpected '{' in C:\wamp64\www\includes\signup.inc.php on line 15" Nothing is showing up in my database and I could use some help. (P.S. I use a wamp server if that has any relevance)

Sign up PHP script(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']);
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);

//Error handlers
//Check for empty fields
if (empty($first) || empty($last) || empty($email) || empty($username) || 
/*LINE 15 THE ERROR IS REFERRING TO*/ (empty($password)) {
    header('Location: ../signup.php?signup=empty');
    exit();
} else {
    //Check is 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=empty');
            exit();
        } else {
            $sql = "SELECT * FROM users WHERE user_username='username'";
            $result = mysqli_query($conn, $sql);
            $resultCheck = mysqli_num_rows($result);

            if ($resultCheck > 0) {
                header('Location: ../signup.php?signup=usertaken');
                exit();
            } else {
                //Hashing the password
                $hashedPassword = password_hash($password, 
PASSWORD_DEFAULT);
                //Insert the user into the database
                $sql = "INSERT INTO users (user_first, user_last, 
user_email, user_username, user_password) VALUES ('$first', '$last', 
'$email', 
'$username' '$hashedPassword');";
                mysqli_query($conn, $sql);
                header('Location: ../signup.php?signup=success');
                exit();
            }
        }
    }
}

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

Database connection(dbh.inc.php)

<?php

$dbServername = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbServername = "loginsystem";

$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, 
$dbServername);

Sign up form(html in PHP file)(signup.php)

<?php include_once 'header.php';?>

<section class="main-container">
<div class="wrapper">
    <h2>Sign Up</h2>
    <form class="Sign" action="includes/signup.inc.php" method="POST">
        <input type="text" name="first" placeholder="First Name"><br>
        <input type="text" name="last" placeholder="Last Name"><br>
        <input type="email" name="email" placeholder="E-mail"><br>
        <input type="text" name="username" placeholder="Username"><br>
        <input type="password" name="password" placeholder="Password"><br>
        <button type="submit" name="submit">Sign Up!</button><br>
    </form>
</div>              
</section>  

<?php include_once 'footer.php';?>

Help would be much appreciated. Thanks!

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • In that line you added the comment, you got an additional `(` and the same with the second `(!preg_match` – Lawrence Cherone Nov 29 '17 at 02:51
  • 2
    Use a a proper code editor which shows you syntax errors, not notepad++ – Lawrence Cherone Nov 29 '17 at 02:52
  • 1
    It would be helpful if you could include just enough to reproduce the problem. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – JonathanDavidArndt Nov 29 '17 at 02:55
  • Your also still open to sql injection and `user_username='username'` as mentioned in your [previous question](https://stackoverflow.com/questions/47543511/php-signup-system-wont-work-phpmyadmin-wampserver) – Lawrence Cherone Nov 29 '17 at 02:55
  • You didn't write the above source code. If you did you should be able to figure out the issue. – Rotimi Nov 29 '17 at 03:09

1 Answers1

0

Its is just a simple typo, so you are missing the closing ) in the if statement.

Change to this

if (empty($first) || empty($last) || empty($email) || empty($username) || 
     empty($password) ) {
    header('Location: ../signup.php?signup=empty');
    exit();
} else {
    ....
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149