Advertisement
Guest User

send_register.php

a guest
Oct 30th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2. if (isset($_POST['nickname']) && $_POST['nickname']) {
  3.     // memasukan file koneksi ke database
  4.     require_once 'config.php';
  5.     // menyimpan variable yang dikirim Form
  6.     $nama = $_POST['nickname'];
  7.     $username = $_POST['username'];
  8.     $password = $_POST['password'];
  9.     $repassword = $_POST['repassword'];
  10.     // cek nilai variable
  11.     if (empty($nama)) {
  12.         header('location: ./register.php?error=' .base64_encode('Nama tidak boleh kosong'));
  13.     }
  14.     if (empty($username)) {
  15.         header('location: ./register.php?error=' .base64_encode('Username tidak boleh kosong'));  
  16.     }
  17.     if (empty($password)) {
  18.         header('location: ./register.php?error=' .base64_encode('Password tidak boleh kosong'));  
  19.     }
  20.     // validasi apakah password dengan repassword sama
  21.     if ($password != $repassword) { // jika tidak sama
  22.         header('location: ./register.php?error=' .base64_encode('Password tidak boleh sama'));  
  23.     }
  24.     // encryption dengan md5
  25.     $password = md5($password);
  26.     $level = 'member'; // default,
  27.     // SQL Insert
  28.     $sql = "INSERT INTO users (nama, username, password, level_user) VALUES ('$nama', '$username', '$password', '$level')";
  29.     $insert = $dbconnect->query($sql);
  30.     // jika gagal
  31.     if (! $insert) {
  32.         echo "<script>alert('".$dbconnect->error."'); window.location.href = './register.php';</script>";
  33.     } else {
  34.         echo "<script>alert('Insert Data Berhasil'); window.location.href = './login.php';</script>";
  35.     }
  36. }
  37. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement