Advertisement
Guest User

Untitled

a guest
Jul 16th, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. session_start();
  2.  
  3. $username ="";
  4. $email = "";
  5. $errors = array();
  6. //connect to the database
  7. $db = mysqli_connect('localhost' , 'root' ,'' ,'registration');
  8.  
  9. // if the register button is clicked
  10. if (isset($_POST['register'])) {
  11. $username = mysqli_real_escape_string($db,$_POST['username']);
  12. $email = mysqli_real_escape_string($db,$_POST['email']);
  13. $password_1 = mysqli_real_escape_string($db,$_POST['password_1']);
  14. $password_2 = mysqli_real_escape_string($db,$_POST['password_2']);
  15.  
  16.  
  17.  
  18. //ensure that form fields are filled properly
  19. if (empty($username)) {
  20. array_push($errors, "Username is required");
  21. }
  22. if (empty($email)) {
  23. array_push($errors, "Email is required");
  24. }
  25. if (empty($password_1)) {
  26. array_push($errors, "Password is required");
  27. }
  28. if ($password_1 != $password_2) {
  29. array_push($errors, "The two passwords do not match");
  30. }
  31.  
  32. // if there are no errors, save user to database
  33. if (count($errors) ==0) {
  34. $password = md5($password_1);
  35. $sql = "INSERT INTO users (username, email, password)
  36. VALUES ('$username', '$email', '$password')";
  37. mysqli_query($db, $sql);
  38. $_SESSION['username'] = $username;
  39. $_SESSION['success'] = "You are logged in";
  40. header('location: index.php');
  41. }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement