Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.60 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ob_start();
  4.     include 'config/koneksi.php';
  5.     include 'media.php';
  6.  
  7.  
  8.     if(!empty($_GET)){
  9.         if($_GET['act'] == 'delete'){
  10.            
  11.             $q = mysqli_query($koneksi,"DELETE FROM user WHERE id='$_GET[id]'");
  12.             if($q){ alert("Success"); header("location:tambahadmin.php"); }
  13.         }  
  14.     }
  15.     if(!empty($_GET['act']) && $_GET['act'] == 'create'){
  16.         if(!empty($_POST)){
  17.             extract($_POST);
  18.             $password = md5($password);
  19.             $q = mysqli_query($koneksi, "INSERT INTO user VALUES(NULL,'$username','$password','$nama_lengkap','$email','$no_telp','$level')");
  20.             if($q){ alert("Success"); header("location:tambahadmin.php"); }
  21.         }
  22.     }
  23.     if(!empty($_GET['act']) && $_GET['act'] == 'edit'){
  24.         if(!empty($_POST)){
  25.             extract($_POST);
  26.             $password = md5($password);
  27.             $q = mysqli_query($koneksi, "UPDATE user SET username='$username',password='$password',nama_lengkap='$nama_lengkap',email='$email',no_telp='$no_telp',level='$level' where id=$_GET[id]") or die(mysql_error());
  28.             if($q){ alert("Success"); header("location:tambahadmin.php"); }
  29.         }
  30.     }
  31. ?>
  32. <!DOCTYPE html>
  33. <html>
  34. <head>
  35.   <title>Untitled Document</title>
  36.    <!-- Required meta tags -->
  37.     <meta charset="utf-8">
  38.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  39.  
  40.     <!-- Bootstrap CSS -->
  41.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
  42.  
  43.     <!-- Fontawesome CSS -->
  44.     <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.11.2/css/all.css" integrity="sha384-KA6wR/X5RY4zFAHpv/CnoG2UW1uogYfdnP67Uv7eULvTveboZJg0qUpmJZb5VqzN" crossorigin="anonymous">
  45.  
  46.  </head>
  47. <body>
  48.  
  49.     <div id="layoutSidenav">
  50.     <div id="layoutSidenav_content">
  51.     <div class="container" style="margin-top: 15px">
  52.     <?php
  53.             $q = mysqli_query($koneksi, "SELECT * FROM user");
  54.             $j = mysqli_num_rows($q);
  55.         ?>
  56.     <h4>Admin (<?php echo ($j>0)?$j:0; ?>)</h4>
  57.         <a class="btn btn-sm btn-primary" href="tambahadmin.php?act=create"><i class="fas fa-plus"></i> Tambah Data</a>
  58.         <hr>
  59.         <?php
  60.             if(!empty($_GET)){
  61.                 if($_GET['act'] == 'create'){
  62.                 ?>
  63.                 <form action="" method="post" enctype="multipart/form-data">
  64.                     <div class="form-row">
  65.                         <div class="form-group col-md-6">
  66.                           <label>Username</label>
  67.                             <input type="text" class="form-control" name="username" required>
  68.                         </div>
  69.                         <div class="form-group col-md-6">
  70.                             <label>Password</label>
  71.                                 <input type="password" class="form-control" name="password" required>
  72.                         </div>
  73.                         <div class="form-group col-md-6">
  74.                             <label>Nama Lengkap</label>
  75.                                 <input type="text" class="form-control" name="nama_lengkap" required>
  76.                         </div>
  77.                         <div class="form-group col-md-6">
  78.                             <label>Email</label>
  79.                                 <input type="email" class="form-control" name="email" required>
  80.                         </div>
  81.                     </div>
  82.                     <div class="form-row">
  83.                        
  84.                         <div class="form-group col-md-6">
  85.                             <label>Nomor Telepon</label>
  86.                                 <input type="text" class="form-control" name="no_telp" required>
  87.                         </div>
  88.                         <div class="form-group col-md-6">
  89.                              <label>Pilih Status</label>
  90.                             <select name="level" required class="form-control custom-select">
  91.                            
  92.                             <option value="pegawai">pegawai</option>
  93.                         </select>
  94.                         </div>
  95.                     </div>
  96.                     <input type="submit" name="form-input" value="Simpan" class="btn btn-primary btn-sm">
  97.                 </form>
  98.                 <br>
  99.                 <?php  
  100.                 }
  101.                 if($_GET['act'] == 'edit'){
  102.                     $data = mysqli_fetch_object(mysqli_query($koneksi,"SELECT * FROM user where id='$_GET[id]'"));
  103.                 ?>
  104.                 <form action="tambahadmin.php?act=edit&&id=<?php echo $_GET['id'] ?>" method="post" enctype="multipart/form-data">
  105.                     <div class="form-row">
  106.                         <div class="form-group col-md-6">
  107.                           <label>Username</label>
  108.                             <input type="text" class="form-control" name="username" value="<?php echo $data->username; ?>" required>
  109.                         </div>
  110.                         <div class="form-group col-md-6">
  111.                           <label>Password</label>
  112.                             <input type="password" class="form-control" name="password" value="<?php echo $data->password; ?>" required>
  113.                         </div>
  114.                         <div class="form-group col-md-6">
  115.                             <label>Nama Lengkap</label>
  116.                                 <input type="text" class="form-control" name="nama_lengkap" value="<?php echo $data->nama_lengkap; ?>" required>
  117.                         </div>
  118.                          <div class="form-group col-md-6">
  119.                             <label>Email</label>
  120.                                 <input type="email" class="form-control" name="email" value="<?php echo $data->email; ?>" required>
  121.                         </div>
  122.                     </div>
  123.                     <div class="form-row">
  124.                        
  125.                         <div class="form-group col-md-6">
  126.                             <label>Nomor Telepon</label>
  127.                                 <input type="text" class="form-control" name="no_telp" value="<?php echo $data->no_telp; ?>" required>
  128.                         </div>
  129.                         <div class="form-group col-md-6">
  130.                             <label>Pilih Status</label>
  131.                             <select name="level" required class="form-control">
  132.                             <option value="<?php echo $data->level; ?>"><?php echo $data->level; ?></option>
  133.                         </select>
  134.                         </div>
  135.                     </div>
  136.                     <input type="submit" name="form-input" value="Simpan" class="btn btn-primary btn-sm">
  137.                 </form>
  138.                 <br>
  139.                 <?php  
  140.                 }
  141.             }
  142.         ?>
  143.         <div class="table-responsive">
  144.             <table class="table table-bordered">
  145.                 <thead>
  146.                     <tr>
  147.                         <th>No</th>
  148.                         <th>Username</th>
  149.                         <!-- <th>Password</th> -->
  150.                         <th>Nama Lengkap</th>
  151.                         <th>Email</th>
  152.                         <th>Nomor Telepon</th>
  153.                         <th>Status</th>
  154.                         <th>Tools</th>
  155.                     </tr>
  156.                 </thead>
  157.                     <tbody>
  158.                         <?php while($data=mysqli_fetch_object($q)){ ?>
  159.                             <tr>
  160.                                 <td><?php echo $no++; ?></td>
  161.                                 <td><?php echo $data->username ?></td>
  162.                                 <!-- <td><?php echo $data->password ?></td> -->
  163.                                 <td><?php echo $data->nama_lengkap ?></td>
  164.                                 <td><?php echo $data->email ?></td>
  165.                                 <td><?php echo $data->no_telp ?></td>
  166.                                 <td><?php echo $data->level ?></td>
  167.                                 <td>
  168.                                     <a class="btn btn-sm btn-info" href="tambahadmin.php?act=edit&&id=<?php echo $data->id ?>" title="Edit Data"><i class="fas fa-edit"></i></a>
  169.                                     <a class="btn btn-sm btn-danger" href="tambahadmin.php?act=delete&&id=<?php echo $data->id ?>" title="Hapus Data"><i class="fas fa-trash"></i></a>
  170.                                 </td>
  171.                             </tr>
  172.                             <?php } ?>
  173.                     </tbody>
  174.                       </table>
  175. </div>
  176.  
  177.     </div></div></div>
  178. </body>
  179. </html>
  180.    <?php
  181.     include "footer.php";
  182. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement