Advertisement
Guest User

Untitled

a guest
Oct 9th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $username = "";
  5. $email = "";
  6. $errors = array();
  7.  
  8. $db = mysqli_connect('localhost', 'root', 'root', 'example')
  9.  
  10.  
  11. if(isset($_POST['register'])) {
  12. $username = mysqli_real_escape_string($db, $_POST['username']);
  13. $email = mysqli_real_escape_string($db, $_POST['email']);
  14. $password = mysqli_real_escape_string($db, $_POST['password']);
  15.  
  16. if(empty($username)) {
  17. array_push($errors, "Username is required");
  18. }
  19. if(empty($email)) {
  20. array_push($errors, "Email is required");
  21. }
  22. if(empty($password)) {
  23. array_push($errors, "Password is required");
  24. }
  25. }
  26.  
  27. if(count($errors) == 0) {
  28. $pass = md5($password);
  29. $query = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$pass')";
  30.  
  31. mysqli_query($db, $query);
  32. }
  33.  
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement