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!