Hey guys,

So as you will tell by my code, I'm dazed and confused on what to do now.

I'm trying to establish a user register form that takes the user data, sanitizes the email address, encrypts the password, and takes the logged in user to index.html. -OR- takes the user back to signUp.html with the error "Passwords must match/username must be longer than 4 characters".

Here is the code I have, any advice at all would be APPRECIATED. I've been struggling with this all day.

Code:
<?php 

	error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
	
	$dbhost = 'localhost';
	$dbuser = 'root';
	$dbpass = '';
	$mysql_database = "21st";
	
	$conn = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Could not connect database");
			mysqli_select_db($conn, $mysql_database) or die("Could not select database");
			
			
	$username = $_POST['username'];
	$email = $_POST['email'];
	$password = $_POST['password'];
	$password2 = $_POST['password2'];

	if ($password != $password2)	{
			header('Location: signUp.html');
	} else	{
		
	if (strlen($username) < 4) 	   {
			header('Location: signUp.html');
	} else	{
		
			$password = md5($password);
			$password2 = md5($password2);
			$sanitized_email = filter_var($email, FILTER_SANITIZE_EMAIL);
			
			$sql = "INSERT INTO members (username, email, password) VALUES ('$username','$email','$password')";	
			mysqli_query($conn, $sql);
			
			header('Location: index.html');
			exit();
		}
	}

?>