Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Declaring variables to prevent errors
- $firstname = ""; //First name
- $lastname = ""; //Last name
- $email= ""; //email
- $password = ""; //password
- $confirmpassword= ""; //confirm password
- $username= ""; //username
- $address= ""; //address
- $mobile= "";//mobile
- $licence_key= "";
- $specialist="";
- $error_array = array(); //Holds error messages
- if(isset($_POST['register_button'])){
- //Registration form values
- //First name
- $firstname = strip_tags($_POST['firstname']); //Remove html tags
- $firstname = str_replace(' ', '', $firstname); //remove spaces
- $firstname = ucfirst(strtolower($firstname)); //Uppercase first letter
- $_SESSION['firstname'] = $firstname; //Stores first name into session variable
- //Last name
- $lastname = strip_tags($_POST['lastname']); //Remove html tags
- $lastname = str_replace(' ', '', $lastname); //remove spaces
- $lastname = ucfirst(strtolower($lastname)); //Uppercase first letter
- $_SESSION['lastname'] = $lastname; //Stores last name into session variable
- //email
- $email = strip_tags($_POST['email']); //Remove html tags
- $email = str_replace(' ', '', $email); //remove spaces
- $email = ucfirst(strtolower($email)); //Uppercase first letter
- $_SESSION['email'] = $email; //Stores email into session variable
- //Password
- $password = strip_tags($_POST['password']); //Remove html tags
- $confirmpassword= strip_tags($_POST['confirmpassword']); //Remove html tags
- //Address
- $address = strip_tags($_POST['address']); //Remove html tags
- $address = str_replace(' ', '', $address); //remove spaces
- $address = ucfirst(strtolower($address)); //Uppercase first letter
- $_SESSION['address'] = $address; //Stores address into session variable
- //Mobile
- $mobile = strip_tags($_POST['mobile']); //Remove html tags
- $mobile = str_replace(' ', '', $mobile); //remove spaces
- $_SESSION['mobile'] = $mobile; //Stores first name into session variable
- //licence key
- $licence_key = strip_tags($_POST['licence_key']); //Remove html tags
- $licence_key = str_replace(' ', '', $licence_key); //remove spaces
- $_SESSION['licence_key'] = $licence_key; //Stores first name into session variable
- //Specilaist
- $specialist = strip_tags($_POST['specialist']); //Remove html tags
- $specialist = str_replace(' ', '', $specialist); //remove spaces
- $specialist = ucfirst(strtolower($specialist)); //Uppercase first letter
- $_SESSION['specialist'] = $specialist; //Stores first name into session variable
- //if($em == $em2) {
- //Check if email is in valid format
- //if(filter_var($em, FILTER_VALIDATE_EMAIL)) {
- //$em = filter_var($em, FILTER_VALIDATE_EMAIL);
- //Check if email already exists
- $email_check = mysqli_query($con, "SELECT email FROM users WHERE email='$email'");
- //Count the number of rows returned
- $num_rows = mysqli_num_rows($email_check);
- if($num_rows > 0) {
- array_push($error_array, "Email already in use<br>");
- }
- }
- else {
- array_push($error_array, "Invalid email format<br>");
- }
- }
- //else {
- //array_push($error_array, "Emails don't match<br>");
- }
- if(strlen($firstname) > 25 || strlen($firstname) < 2) {
- array_push($error_array, "Your first name must be between 2 and 25 characters<br>");
- }
- if(strlen($lastname) > 25 || strlen($lastname) < 2) {
- array_push($error_array, "Your last name must be between 2 and 25 characters<br>");
- }
- if($password != $confirmpassword) {
- array_push($error_array, "Your passwords do not match<br>");
- }
- else {
- if(preg_match('/[^A-Za-z0-9]/', $password)) {
- array_push($error_array, "Your password can only contain english characters or numbers<br>");
- }
- }
- if(strlen($password > 30 || strlen($password) < 5)) {
- array_push($error_array, "Your password must be betwen 5 and 30 characters<br>");
- }
- if(empty($error_array)) {
- $password = md5($password); //Encrypt password before sending to database
- //Generate username by concatenating first name and last name
- $username = strtolower($fname . "_" . $lname);
- $check_username_query = mysqli_query($con, "SELECT username FROM users WHERE username='$username'");
- $i = 0;
- //if username exists add number to username
- while(mysqli_num_rows($check_username_query) != 0) {
- $i++; //Add 1 to i
- $username = $username . "_" . $i;
- $check_username_query = mysqli_query($con, "SELECT username FROM users WHERE username='$username'");
- }
- //Profile picture assignment
- //$rand = rand(1, 2); //Random number between 1 and 2
- //if($rand == 1)
- // $profile_pic = "assets/images/profile_pics/defaults/head_deep_blue.png";
- //else if($rand == 2)
- //$profile_pic = "assets/images/profile_pics/defaults/head_emerald.png";
- $query = mysqli_query($con, "INSERT INTO users VALUES ('', '$firstname', '$lastname', '$username', '$email', '$password', '0', '0', 'no', ',')");
- array_push($error_array, "<span style='color: #14C800;'>You're all set! Goahead and login!</span><br>");
- //Clear session variables
- $_SESSION['firstname'] = "";
- $_SESSION['lastname'] = "";
- $_SESSION['email'] = "";
- $_SESSION['username'] = "";
- $_SESSION['address'] = "";
- $_SESSION['mobile'] = "";
- $_SESSION['licence_key'] = "";
- $_SESSION['specialist'] = "";
- }
- }
- ?>
Add Comment
Please, Sign In to add comment