Click here to Skip to main content
15,746,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
PHP
  1  prepare("SELECT * FROM users WHERE email=?")){
  2  		$error = '';
  3  		//Bind parameters (s=mstring, i= int, b=blob,etc),in our case the username is a string so we use "s"
  4  		$query->bind_param('s',$email);
  5  		$query->execute();
  6  		//Store the result so we can check if the account exists in the database.
  7  		$->store_result();
  8  		if ($query->num_rows > 0) {
  9  			$error .= 'The email address is already registered!';
 10  		}else{
 11  			// Validate password
 12  			if (strlen($password) Password must have atleast 6 characters.';
 13  			}
 14  
 15  			//Validate confirm password
 16  			if (empty($confirm_password)){
 17  				$error .= 'Please enter confirm password.';
 18  			} else {
 19  				if (empty($error) && ($password != $confirm_password)){
 20  					$error .= 'Password did not match.';
 21  				}
 22  			}
 23  			if (empty($error)) {
 24  				$insertQuery = $db->prepare("INSERT INTO users (name,email,password)VALUES (?,?,?);");
 25  				$insertQuery->bind_param("sss", $fullname, $email, $password_hash);
 26  				$result = $insertQuery->execute();
 27  				if ($result) {
 28  					$error .= 'Your registration was successful!';
 29  				} else {
 30  					$error .= 'Something went wrong!';
 31  				}
 32  			}
 33  		}
 34  
 35  	}
 36  	$query->close();
 37  	$insertQuery->close();
 38  	// Close DB connection
 39  	mysqli_close($db);
 40  }
>?




Sign Up






Register
Please fill this form to create an account.




Full Name



Email Address



Password



Confirm Password





Already have an account? Login here

What I have tried:

Parse error: syntax error, unexpected token "->", expecting variable or "{" or "$" in C:\xampp\htdocs\Magosi carrental\register.php on line 20
Posted
Updated 15-Jul-22 8:36am
v2
Comments
0x01AA 15-Jul-22 13:22pm    
After applying code tags it looks the problem starts in line 12 ;)
Austoman 15-Jul-22 13:34pm    
how do i solve the problem
0x01AA 15-Jul-22 13:52pm    
With something like:
// Validate password
if (strlen($password) < 6){
$error .= 'Password must have atleast 6 characters.';
}
else ...
Austoman 15-Jul-22 14:11pm    
can you solve it for me cause it still gives me problems
0x01AA 15-Jul-22 14:17pm    
I hate that intendation style ;) Try that
prepare("SELECT * FROM users WHERE email=?")){
		$error = '';
		//Bind parameters (s=mstring, i= int, b=blob,etc),in our case the username is a string so we use "s"
		$query->bind_param('s',$email);
		$query->execute();
		//Store the result so we can check if the account exists in the database.
		$->store_result();
		if ($query->num_rows > 0) {
			$error .= 'The email address is already registered!';
		}else{
			// Validate password
			if (strlen($password) < 6){
				$error .= 'Password must have atleast 6 characters.';
			}

			//Validate confirm password
			elseif (empty($confirm_password)){
				$error .= 'Please enter confirm password.';
			} else {
				if (empty($error) && ($password != $confirm_password)){
					$error .= 'Password did not match.';
				}
			}
			if (empty($error)) {
				$insertQuery = $db->prepare("INSERT INTO users (name,email,password)VALUES (?,?,?);");
				$insertQuery->bind_param("sss", $fullname, $email, $password_hash);
				$result = $insertQuery->execute();
				if ($result) {
					$error .= 'Your registration was successful!';
				} else {
					$error .= 'Something went wrong!';
				}
			}
		}

	}
	$query->close();
	$insertQuery->close();
	// Close DB connection
	mysqli_close($db);
}

1 solution

See comments to the question. Looks like a trivial syntax thing. A fast and dirty solution would be the following:
prepare("SELECT * FROM users WHERE email=?")){
		$error = '';
		//Bind parameters (s=mstring, i= int, b=blob,etc),in our case the username is a string so we use "s"
		$query->bind_param('s',$email);
		$query->execute();
		//Store the result so we can check if the account exists in the database.
		$->store_result();
		if ($query->num_rows > 0) {
			$error .= 'The email address is already registered!';
		}else{
			// Validate password
			if (strlen($password) < 6){
				$error .= 'Password must have atleast 6 characters.';
			}

			//Validate confirm password
			elseif (empty($confirm_password)){
				$error .= 'Please enter confirm password.';
			} else {
				if (empty($error) && ($password != $confirm_password)){
					$error .= 'Password did not match.';
				}
			}
			if (empty($error)) {
				$insertQuery = $db->prepare("INSERT INTO users (name,email,password)VALUES (?,?,?);");
				$insertQuery->bind_param("sss", $fullname, $email, $password_hash);
				$result = $insertQuery->execute();
				if ($result) {
					$error .= 'Your registration was successful!';
				} else {
					$error .= 'Something went wrong!';
				}
			}
		}

	}
	$query->close();
	$insertQuery->close();
	// Close DB connection
	mysqli_close($db);
}


Of course some else {if ... could be simplified by using elseif.
 
Share this answer
 

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