'; echo 'console.log('. json_encode( $data ) .')'; echo ''; } // Define variables and initialize with empty values $username = $password = $confirm_password = $firstname = $email = $lastname = ""; $username_err = $password_err = $confirm_password_err = ""; $firstname_err = $email_err = $home_address = ""; $home_phone = 0; $cell_phone = 0; // Processing form data when form is submitted if($_SERVER["REQUEST_METHOD"] == "POST"){ //validate email if(empty(trim($_POST["email"]))){ $email_err = "Please enter a Email."; } //validate firstname if(empty(trim($_POST["firstname"]))){ $firstname_err = "Please enter a Firstname."; } // Validate username if(empty(trim($_POST["username"]))){ $username_err = "Please enter a username."; } else{ // Prepare a select statement $sql = "SELECT id FROM users WHERE username = ?"; if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "s", $param_username); // Set parameters $param_username = trim($_POST["username"]); // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ /* store result */ mysqli_stmt_store_result($stmt); if(mysqli_stmt_num_rows($stmt) == 1){ $username_err = "This username is already taken."; } else{ $username = trim($_POST["username"]); } } else{ echo "Oops! Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Validate password if(empty(trim($_POST["password"]))){ $password_err = "Please enter a password."; } elseif(strlen(trim($_POST["password"])) < 10){ $password_err = "Password must have atleast 10 characters."; } elseif(!preg_match("#[A-Z]+#",$password)){ $password_err = "Your Password Must Contain At Least 1 Capital Letter!"; } elseif(!preg_match("!@#$%^&*",$password)){ $password_err = "Your Password Must Contain At Least 1 Special Character!"; } 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."; } } // //Validates password & confirm passwords. // if(!empty($_POST["password"]) && ($_POST["password"] == $_POST["confirm_password"])) { // $password = test_input($_POST["password"]); // $cpassword = test_input($_POST["confirm_password"]); // if (strlen($_POST["password"]) <= '10') { // $password_err = "Your Password Must Contain At Least 10 Characters!"; // } // elseif(!preg_match("#[A-Z]+#",$password)) { // $password_err = "Your Password Must Contain At Least 1 Capital Letter!"; // } // elseif(!preg_match("!@#$%^&*",$password)) { // $password_err = "Your Password Must Contain At Least 1 special Letter!"; // } else { // $confirm_password_err = "Please Check You've Entered Or Confirmed Your Password!"; // } // } // Check input errors before inserting in database if(empty($username_err) && empty($password_err) && empty($confirm_password_err) && empty($password_err) && empty($firstname_err) && empty($email_err)){ // Prepare an insert statement //echo "CHECK 21111111"; $sql = "INSERT INTO users (username, password, firstname, email, last_name, home_address, home_phone, cell_phone) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; $firstname = trim($_POST["firstname"]); $email = trim($_POST["email"]); $lastname = trim($_POST["lastname"]); $home_address = trim($_POST["home_address"]); $home_phone = trim($_POST["home_phone"]); $cell_phone = trim($_POST["cell_phone"]); if($stmt = mysqli_prepare($link, $sql)){ // Bind variables to the prepared statement as parameters mysqli_stmt_bind_param($stmt, "ssssssii", $param_username, $param_password, $param_firstname, $param_email, $param_lastname, $param_home_address, $param_home_phone, $param_cell_phone); // Set parameters $param_username = $username; $param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash $param_firstname = $firstname; $param_email = $email; $param_lastname = $lastname; $param_home_address = $home_address; $param_home_phone = $home_phone; $param_cell_phone = $cell_phone; // Attempt to execute the prepared statement if(mysqli_stmt_execute($stmt)){ // Redirect to login page header("location: login.php"); } else{ echo "Something went wrong. Please try again later."; } // Close statement mysqli_stmt_close($stmt); } } // Close connection mysqli_close($link); } ?> Contact Us

Kopi Luwak

Coffee

Sign Up

Please fill this form to create an account.

" method="post">

Already have an account? Login here.