Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
<pre>
<?php
function emptyInputSignup($name, $surname, $contact_Number, $email_Address, $organisation, $position, $username,  $password, $repeat_Password){
    $result = "";
    if(empty($name) || empty($surname) || empty($contact_Number) || empty($email_Address) || empty($organisation) || empty($position) || empty($password) || empty($repeat_Password) || empty($surname)){
        $result = true;
    }
    else{
        $result = false;
    }
    return $result;
}

function invalidUsername($username){
    $result = "";
    $pattern = "/^[a-zA-Z0-9]*$/";
    if(!preg_match($pattern, $username)){
        $result = true;
    }
    else{
        $result = false;
    }
    return $result;
}

 function invalidEmail($email_Address){
    $result = "";
    if(!filter_var($email_Address, FILTER_VALIDATE_EMAIL)){
        $result = true;
    }
    else{
        $result = false;
    }
    return $result;
}

function pswMatch($password, $repeat_Password) {
    $result = "";
    if ($password !== $repeat_Password) {
        $result = true;
    } 
    else {
        $result = false;
    }
    return $result;
}

 function UserNameExists($conn, $username, $email_Address){ 
    $sql = "SELECT * FROM user WHERE Username = ? OR Email = ?;";
    $stmt = mysqli_stmt_init($conn);

    if(!mysqli_stmt_prepare($stmt, $sql)){
        header("Location: ../pages/Users/Registration_Form.php?error=SqlStatementFailed");
        exit();
    }

    mysqli_stmt_bind_param($stmt, "ss",  $username, $email_Address);
    mysqli_stmt_execute($stmt);

    $resultData = mysqli_stmt_get_result($stmt);

    if($row = mysqli_fetch_assoc($resultData)){
        return $row;
    }
    else{
        $result = false;
        return $result;
    }
    mysqli_stmt_close($stmt);
}


function createUser($conn, $name, $surname, $contact_Number, $email_Address, $organisation, $position, $username,  $password, $repeat_Password){
    
$sql = "INSERT INTO user (Name, Surname, Contact_Number, Email, Organization, Position, Username, Password) VALUES (?,?,?,?,?,?,?,?);";
$stmt = mysqli_stmt_init($conn);

if(!mysqli_stmt_prepare($stmt, $sql)){
    header("Location: ../pages/Users/Registration_Form.php?error=SqlStatementFailed");
    exit();
}

$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

mysqli_stmt_bind_param($stmt, "ssssssss",  $name, $surname, $contact_Number, $email_Address, $organisation, $position, $username,  $hashedPassword);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
header("Location: ../pages/Users/Registration_Form.php?error=noErrors");
exit();
}


What I have tried:

The function pswMatch states the following:
'}' expected.


I have gone through the code to double check all brackets. I have even rewritten the function but I still get the same error message.
Posted
Comments
Luc Pattyn 3-Oct-22 22:03pm    
I see nothing wrong in your brackets.

A
'}' expected
message does not imply an imbalance of brackets, it simply states it was expecting a '}' and got something else. Are you sure there aren't any unexpected characters in front of one of your brackets, even unprintable ones?

Furthermore, you can simplify your code a lot, e.g.:

function pswMatch($password, $repeat_Password) {
return $password !== $repeat_Password;
}

And finally, when such function returns false on a match, then its name is wrong; it should be called pswMismatch, so calling code could look like:

if (pswMismatch($a,$b)) echo "password mismatch";

PS: you have empty($surname) twice, and are lacking an empty($username).
Luc Pattyn 3-Oct-22 22:22pm    
forgot to mention: you have an unreachable statement:
mysqli_stmt_close($stmt);
Member 15627495 4-Oct-22 0:07am    
an if( statement ) always return true or false.
you can let
$result="";$result = true;return $result;because It's too useless

and use :
return false; // or // return true;
Richard MacCutchan 4-Oct-22 4:34am    
I just pasted that code into PHP and it parses successfully. Are you sure that is exactly what you are trying to run?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900