Hi all not only am I new to the forum (my name is Alex and I am 16 years) I am trying to learn PHP, I feel I am mastering HTML and CSS (not 100% there still finding this I didn't know) and felt PHP is the natural progression in becoming an around web developer.

For the last two days, I have been staring at the code below and getting nowhere. I am getting a

PHP Parse error: syntax error, unexpected 'else' (T_ELSE) in Standard input code on line 8

I cannot find where I am missing '{' or '}'.
I know you must get loads joining to ask the same questions. I would be truly grateful if someone could have a look over the code and point out where I am going wrong. Thanks once again for your help.

<?php

function emptyInputRegister($name, $surname, $userdob, $userUid, $houseNameNumber, $address, $postcode, $email, $email2, $Pwd, $Pwd2){
	$result;
	if (empty($name) || empty($surname) || empty($userdob) || empty($userUid) || empty($houseNameNumber) || empty($address) || empty($postcode) || (empty($email) || empty($email2) || empty($Pwd) || empty($Pwd2)) {

	$result = true;
} else {
	$result = false;
}
return $result;
}

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

function invalidEmail($email){
	$result;
	if (!filter_var($email, FILLTER_VALIDATE_EMAIL)) {
		$result = true;
	}else{
		$result = false
	} return $result
}

function emailMatch($email, $email2){
	$result;
	if ($email !== $email2) {
		$result = true;
	}else{
		$result = false
	} return $result
}

function passwordMatch($Pwd, $Pwd2){
	$result;
	if ($pwd !== $pwd2) {
		$result = true;
	}else{
		$result = false
	} return $result
}

function userUidExists($conn, $userUid, $email){
	$sql = "SELECT * FORM user WHERE userUid = ? OR userEmail = ?;";
	$stmt = mysqli_stmt_init($conn);
	if (!mysqli_stmt_prepare($stmt, $sql)) {
		header("location: ../login/login.php?error=stmtfailed");
		exit();
	}

mysqli_stmt_bind_param($stmt, "ss" $userUid, $email);
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($userUid, $name, $middleName, $surname, $Email, $pwd, $userdob, $House, $Address, $address2, $city, $postcode) {
	$sql = "INSERT INTO users (userUid, userName, userMiddelName, userSurname, userEmail, userpwd, userdob, userHouse, userAddress, useraddress2, userCity, userPostcoder) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
	$stmt = mysqli_stmt_init($conn);
	if (!mysqli_stmt_prepare($stmt, $sql)) {
		header("location: ../login/login.php?error=stmtfailed");
		exit();
	}

$hashedpwd = password_hash($pwd, PASSWORD_DEFAULT);

mysqli_stmt_bind_param($stmt, "ssssssssssss" $userUid, $name, $middleName, $surname, $Email, $hashedpwd, $userdob, $House, $Address, $address2, $city, $postcode);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
header("location: ../login/login.php?error=none");
exit();

mackayajmc
Welcome to the forums. I just edited your post to use this forum's [code]...[/code] tags around the code block (instead of the single back-ticks that the </> button in the edit box uses), in order to improved readability.

Now I'll take a look at the question and see if I have an answer. 😉

    Your initial problem is an extraneous ( before empty($email) in that big if(...) condition on line 5. After you fix that, you'll find problems wherever you have this pattern, due to no ; terminating those two commands:

    	}else{
    		$result = false
    	} return $result
    

    A couple tips:

    You could simplify those invalid*() functions to something like the following:

    function invalidUserUid($userUid){
    	return !preg_match("/^[a-zA-Z0-9]*$/", $userUid));
    }
    

    I might tweak that first function to something like this, for less repetition and improved readbility:

    function emptyInputRegister(
      $name,
      $surname,
      $userdob,
      $userUid,
      $houseNameNumber,
      $address,
      $postcode,
      $email,
      $email2,
      $Pwd,
      $Pwd2
    ) {
      foreach(func_get_args() as $arg) {
        if(empty($arg)) {
          return true;
        }
      }
      return false;
    }
    

    Hope that helps.

      PS: Note that with that emptyInutRegister() function, if one of those values is all spaces, it will be considered "valid". If that's a concern, you could change it to the following instead of using the empty() function:

          if(trim($arg) === '') { // note use of the === operator to include type-matching
            return true;
          }
      
        Write a Reply...