= 1) { $username_err = "This email is already taken."; } else { $username = trim($_POST["username"]); } } // Validate password if (empty(trim($_POST["password"]))) { $password_err = "Please enter a password."; } elseif (strlen(trim($_POST["password"])) < $MINIMAL_PASSWORD_LENGTH) { $password_err = "Password must have atleast $MINIMAL_PASSWORD_LENGTH characters."; } else { $password = trim($_POST["password"]); } // Validate confirm password if (empty(trim($_POST["confirm_password"]))) { $confirm_password_err = "Please confirm password."; } else { $confirm_password = trim($_POST["confirm_password"]); if (empty($password_err) && ($password != $confirm_password)) { $confirm_password_err = "Password did not match."; } } if (empty(trim($_POST["first_name"]))) { $first_name_err = "Please input your first name."; } else if (strlen(trim($_POST["first_name"])) > 255){ $first_name_err = "Too long."; } else { $first_name = trim($_POST["first_name"]); } if (empty(trim($_POST["last_name"]))) { $last_name_err = "Please input your last name."; } else if (strlen(trim($_POST["last_name"])) > 255){ $last_name_err = "Too long."; } else { $last_name = trim($_POST["last_name"]); } // Check input errors before inserting in database if ( empty($username_err) && empty($password_err) && empty($confirm_password_err) && empty($first_name_err) && empty($last_name_err) ) { if (add_user($username, $first_name, $last_name, $password)) { // Redirect to login page header("location: login.php"); } else { echo "Something went wrong. Please try again later."; } } } ?>
Please fill this form to create an account.