diff --git a/register.php b/register.php new file mode 100644 index 0000000..ff2529a --- /dev/null +++ b/register.php @@ -0,0 +1,134 @@ += 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"])) < 6) { + $password_err = "Password must have atleast 6 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 { + $first_name = trim($_POST["first_name"]); + } + + if (empty(trim($_POST["last_name"]))) { + $last_name_err = "Please input your last name."; + } 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."; + } + } +} +?> + + + + + + + Sign Up + + + + + +
+

Sign Up

+

Please fill this form to create an account.

+
" method="post"> +
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + +
+

Already have an account? Login here.

+
+
+ + + \ No newline at end of file