SHARE
TWEET

Untitled

a guest Nov 6th, 2018 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. session_start();
  3.  
  4. // initializing variables
  5. $fullname = "";
  6. $username = "";
  7. $password    = "";
  8. $errors = array();
  9.  
  10. // connect to the database
  11. $db = mysqli_connect('localhost', 'root', '', 'register');
  12.  
  13. // REGISTER USER
  14. if (isset($_POST['reg_user']))
  15.   {
  16.   // receive all input values from the form
  17.   $fullname = mysqli_real_escape_string($db, $_POST['fullname']);
  18.   $username = mysqli_real_escape_string($db, $_POST['username']);
  19.   $password = mysqli_real_escape_string($db, $_POST['password']);
  20.  
  21.   // form validation
  22.   if (empty($fullname)) { array_push($errors, "Full name is requires"); }
  23.   if (empty($username)) { array_push($errors, "Username is required"); }
  24.   if (empty($password)) { array_push($errors, "Password is required"); }
  25.   }
  26.  
  27.   //database check
  28.   $user_check_query = "SELECT * FROM users WHERE username=$username";
  29.   $result = mysqli_query($db, $user_check_query);
  30.   $user = "mysqli_fetch_assoc($result)";
  31.  
  32.  
  33.     if ([username]==$username) { array_push($errors, "username is already taken"); }
  34.  
  35.  
  36.  
  37.   if (count($errors) == 0)
  38.   {
  39.     $password = md5($password);
  40.  
  41.     $query = "INSERT INTO users (fullname, username, password) VALUES('$fullname', '$username', '$password')";
  42.     mysqli_query($db, $query);
  43.     $_SESSION[username] = $username;
  44.     $_SESSION[success] = "You are now logged in";
  45.     header('location: index.html');
  46.   }
  47.  
  48.  
  49. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top