Guest User

Untitled

a guest
Nov 26th, 2017
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2. //nama file : simpan_registrasi.php
  3. require("config.php");
  4. require("config_database.php");
  5.  
  6. if(isset($_POST['submit'])){
  7. $username = $_POST['username'];
  8. //OPTIONAl
  9. $username = trim($username); // menghilangkan spasi didepna dan dibelakang teks
  10. $username = strip_tags($username); //membuat tag html pada teks
  11. /* SILAKAN PELAJAROI FUNGSI htmlspecialchars, htmlspecialchars_decode,htmlentities, html_entity_decode */
  12.  
  13. $password1 = $_POST['password'];
  14. $password2 = $_POST['password'];
  15.  
  16. if($password1 != $password2){
  17. //password tidak sama
  18.  
  19. echo "Password yang anda masukkan tidak sama!";
  20. echo "<br/><a href=''> Coba Lagi</a>";
  21. } else {
  22. //HASH PASSWORD
  23. $password = md5($password1); //md5
  24. //$password = sha1($password1); //sha1
  25.  
  26. //query sql INSERT
  27. $sql = "INSERT INTO users (username, password) values('".$username."', '"$password."')";
  28. //jalankan query INSERT
  29. $result = mysqli_query($conn, $sql);
  30.  
  31. if($result){
  32. echo "Data USER berhasil disimpan, <a href=''>lihat data<a/>";
  33.  
  34. } else {
  35. echo "Data USER gagal disimpan, <a href=''>Coba Lagi</a>";
  36. echo "<br/>";
  37. echo ("Error description: ". mysqli_error)$conn));
  38. }
  39. }
  40. }else {
  41. //kembalikan lagi kehalaman register / users(redirect)
  42. header('Location: '.BASE_URL.'/register.php');
  43. }
  44. ?>
Add Comment
Please, Sign In to add comment