Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'config/koneksi.php';
- include 'media.php';
- if(!empty($_GET)){
- if($_GET['act'] == 'delete'){
- $q = mysqli_query($koneksi,"DELETE FROM user WHERE id='$_GET[id]'");
- if($q){ alert("Success"); redir("tambahadmin.php"); }
- }
- }
- if(!empty($_GET['act']) && $_GET['act'] == 'create'){
- if(!empty($_POST)){
- extract($_POST);
- $password = md5($password);
- $q = mysqli_query($koneksi, "INSERT INTO user Values(NULL,'$username','$password','$nama_lengkap','$email','$no_telp','$level')");
- if($q){ alert("Success"); redir("tambahadmin.php"); }
- }
- }
- if(!empty($_GET['act']) && $_GET['act'] == 'edit'){
- if(!empty($_POST)){
- extract($_POST);
- $password = md5($password);
- $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());
- if($q){ alert("Success"); redir("tambahadmin.php"); }
- }
- }
- ?>
- <div id="layoutSidenav">
- <div id="layoutSidenav_content">
- <div class="container" style="margin-top: 45px">
- <?php
- $q = mysqli_query($koneksi, "SELECT * FROM user");
- $j = mysqli_num_rows($q);
- ?>
- <h4>Admin (<?php echo ($j>0)?$j:0; ?>)</h4>
- <a class="btn btn-sm btn-primary" href="tambahadmin.php?act=create"><i class="fas fa-plus"></i> Tambah Data</a>
- <hr>
- <?php
- if(!empty($_GET)){
- if($_GET['act'] == 'create'){
- ?>
- <form action="" method="post" enctype="multipart/form-data">
- <div class="form-row">
- <div class="form-group col-md-6">
- <label>Username</label>
- <input type="text" class="form-control" name="username" required>
- </div>
- <div class="form-group col-md-6">
- <label>Password</label>
- <input type="password" class="form-control" name="password" required>
- </div>
- <div class="form-group col-md-6">
- <label>Nama Lengkap</label>
- <input type="text" class="form-control" name="nama_lengkap" required>
- </div>
- <div class="form-group col-md-6">
- <label>Email</label>
- <input type="email" class="form-control" name="email" required>
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-6">
- <label>Nomor Telepon</label>
- <input type="text" class="form-control" name="no_telp" required>
- </div>
- <div class="form-group col-md-6">
- <label>Pilih Status</label>
- <select name="level" required class="form-control custom-select">
- <option value="Pegawai">Pegawai</option>
- </select>
- </div>
- </div>
- <input type="submit" name="form-input" value="Simpan" class="btn btn-primary btn-sm">
- </form>
- <br>
- <?php
- }
- if($_GET['act'] == 'edit'){
- $data = mysqli_fetch_object(mysqli_query($koneksi,"SELECT * FROM user where id='$_GET[id]'"));
- ?>
- <form action="tambahadmin.php?act=edit&&id=<?php echo $_GET['id'] ?>" method="post" enctype="multipart/form-data">
- <div class="form-row">
- <div class="form-group col-md-6">
- <label>Username</label>
- <input type="text" class="form-control" name="username" value="<?php echo $data->username; ?>" required>
- </div>
- <div class="form-group col-md-6">
- <label>Password</label>
- <input type="password" class="form-control" name="password" value="<?php echo $data->password; ?>" required>
- </div>
- <div class="form-group col-md-6">
- <label>Nama Lengkap</label>
- <input type="text" class="form-control" name="nama_lengkap" value="<?php echo $data->nama_lengkap; ?>" required>
- </div>
- <div class="form-group col-md-6">
- <label>Email</label>
- <input type="email" class="form-control" name="email" value="<?php echo $data->email; ?>" required>
- </div>
- </div>
- <div class="form-row">
- <div class="form-group col-md-6">
- <label>Nomor Telepon</label>
- <input type="text" class="form-control" name="no_telp" value="<?php echo $data->no_telp; ?>" required>
- </div>
- <div class="form-group col-md-6">
- <label>Pilih Status</label>
- <select name="level" required class="form-control">
- <option value="<?php echo $data->level; ?>"><?php echo $data->level; ?></option>
- </select>
- </div>
- </div>
- <input type="submit" name="form-input" value="Simpan" class="btn btn-primary btn-sm">
- </form>
- <br>
- <?php
- }
- }
- ?>
- <div class="table-responsive">
- <table class="table table-bordered">
- <thead>
- <tr>
- <th>No</th>
- <th>Username</th>
- <!-- <th>Password</th> -->
- <th>Nama Lengkap</th>
- <th>Email</th>
- <th>Nomor Telepon</th>
- <th>Status</th>
- <th>Tools</th>
- </tr>
- </thead>
- <tbody>
- <?php while($data=mysqli_fetch_object($q)){ ?>
- <tr>
- <td><?php echo $no++; ?></td>
- <td><?php echo $data->username ?></td>
- <!-- <td><?php echo $data->password ?></td> -->
- <td><?php echo $data->nama_lengkap ?></td>
- <td><?php echo $data->email ?></td>
- <td><?php echo $data->no_telp ?></td>
- <td><?php echo $data->level ?></td>
- <td>
- <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>
- <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>
- </td>
- </tr>
- <?php } ?>
- </tbody>
- </table>
- </div>
- </div></div></div>
- <?php
- include "footer.php";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement