Advertisement
wahyu_f14

login

Aug 28th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. if (isset($_POST['login'])) {
  2.     $username    = $_POST['username'];
  3.     $password    = $_POST['password'];
  4.    
  5.     $get_data = mysqli_query($db, "SELECT * FROM pengguna WHERE username='$username'");
  6.     $row_data = mysqli_num_rows($get_data);
  7.  
  8.     if ($row_data > 0){
  9.       while($data = mysqli_fetch_array($get_data)){
  10.         $db_id            = $data['id'];
  11.         $db_username      = $data['username'];
  12.         $db_password      = $data['password'];
  13.         $db_role          = $data['role'];
  14.       }
  15.       if ($username==$db_username && $password==$db_password){
  16.         if ($db_role=='admin') {
  17.           $_SESSION['profil-id']         = $db_id;
  18.           $_SESSION['profil-username']   = $username;
  19.           $_SESSION['profil-role']       = $db_role;
  20.  
  21.           header('location:index.php');
  22.         }
  23.       } else {
  24.         echo "<script>alert('Password salah !')</script>";
  25.       }
  26.     } else {
  27.       echo "<script>alert('Username tidak terdaftar !')</script>";
  28.     }
  29.   }
  30.   ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement