BintangSatrio

Untitled

Dec 8th, 2019
289
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. $conn = mysqli_connect("localhost","root","","project");
  3.  
  4. function registrasi($data){
  5. global $conn;
  6.  
  7. $username = strtolower(stripslashes($data["username"]));
  8. $password = mysqli_real_escape_string($conn, $data["password"]);
  9. $password2 = mysqli_real_escape_string($conn, $data["password2"]);
  10. $email = strtolower(stripslashes($data["email"]));
  11.  
  12. //anti double user
  13. $result = mysqli_query($conn, "SELECT username FROM users_admin WHERE username = '$username'");
  14. if( mysqli_fetch_assoc($result)){
  15. echo "<script>
  16. alert('Username Sudah Terpakai');
  17. </script>";
  18. return false;
  19. }
  20. $result = mysqli_query($conn, "SELECT email FROM users_admin WHERE email = '$email'");
  21. if( mysqli_fetch_assoc($result)){
  22. echo "<script>
  23. alert('Gmail Sudah Digunakan');
  24. </script>";
  25. return false;
  26. }
  27.  
  28.  
  29. if ( $password != $password2 ) {
  30. echo "<script>
  31. alert('konfirmasi password tidak sesuai');
  32. </script>";
  33. return false;
  34. }
  35. //encrypting
  36. $password = password_hash($password, PASSWORD_DEFAULT);
  37.  
  38. //add new users
  39. mysqli_query($conn, "INSERT INTO users_admin VALUES('', '$username', '$password', '$email')");
  40. return mysqli_affected_rows($conn);
  41. }
  42. ?>
RAW Paste Data