I have looked through my code and I don't know why this error keeps arising.
The exact error message I get 'Parse error: syntax error, unexpected end of file in C:\wamp\www\includes\functions.inc.php on line 92'
This is my code:
<?php
#since this file contains solely PHP there is no need for the closing tag
#by convention it is better to check if something fails first then succeeds
function emptyInputSignup($username, $password, $passwordRepeat){
$result = Null;
if (empty($username) || empty($password) || empty($passwordRepeat)){
$result = true;
}
else{
$result = false;
}
return result;
}
function invalidUsername($username){
$result = Null;
#if there is a mistake
if (!preg_match("/^[a-zA-Z0-9]*$/", $username)){
$result = true;
}
else{
$result = false;
}
return result;
}
function passwordMatch($password, $passwordRepeat){
$result = Null;
#if there has been a mistake
if ($password !== $passwordRepeat){
$result = true;
}
else{
$result = false;
}
return result;
}
function usernameExists($conn, $username){
$sql = "SELECT * FROM users WHERE username = ?";
#we have created a prepared statement to prevent SQL injections
$stmt = mysqli_stmt_init($conn);
$result = Null;
if (!mysqli_stmt_prepare($stmt, $sql)){
header("location: ../signup.php?error=stmtfailed");
exit();
}
mysqli_stmt_bind_param($stmt, "s", $username);
mysqli_stmt_execute($stmt);
$resultData = mysqli_stmt_get_result();
if($row = mysqli_fetch_assoc($resultData)){
return $row;
}
else{
$result = false;
return $result;
}
function passwordValid($password){
$result = Null;
#if there is a mistake
if (strlen($password) <= 5 && !preg_match("~[0-9]+~", $password)){
$result = true;
}
else{
$result = false;
}
return result;
}
This is the function where I think the error is located in.
function createUser($conn, $username, $password){
$sql = "INSERT INTO users (username, password) VALUES (?, ?)";
#we have created a prepared statement to prevent SQL injections
$stmt = mysqli_stmt_init($conn);
#this checks if the statement is feasible
if (!mysqli_stmt_prepare($stmt, $sql)){
header("location: ../signup.php?error=stmtfailed");
exit();
}
#returns hash of a password
#this inbuilt function is constantly updated
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
mysqli_stmt_bind_param($stmt, "ss", $username, $hashedPassword);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
header("location: ../signup.php?error=none");
exit;
} #this is line 92 but I do not see where the issue is here
I have done some research on how this error is caused by a missing bracket and/or the state of the php.ini however short_open_tag was already set as on. What caused the error?