Advertisement
WorseG

plimbli k_user

Jan 24th, 2019
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.82 KB | None | 0 0
  1. <?php include "config/koneksi.php";
  2. if(isset($_GET['hapus'])){
  3.     $hapus="delete from user where id='$_GET[id]'";
  4.     $war=mysqli_query($con,$hapus);
  5.     if($war){
  6.         echo "<script>alert('Data Terhapus')</script>";
  7.     }
  8. }
  9. if(isset($_POST['simpan'])){
  10.     $sim="insert into user values (null,'$_POST[username]','$_POST[password]')";
  11.     $pan=mysqli_query($con,$sim);
  12.     if($pan){
  13.         echo "<script>alert('Data Tersimpan')</script>";
  14.         echo "<script>document.location.href='k_user.php';</script>";
  15. }
  16. }
  17. if (isset($_GET['edit'])) {
  18.         $et = "SELECT * FROM user WHERE id = '$_GET[id]'";
  19.         $it = mysqli_query($con,$et);
  20.         $edit = mysqli_fetch_array($it);
  21.     }
  22. if (isset($_POST['update'])) {
  23.     $up = "update user set nama='$_POST[nama_user]',username='$_POST[username]',password='$_POST[password]' WHERE id = '$_POST[kode_user]'";
  24.     $da = mysqli_query($con,$up);
  25.     if($da){
  26.         echo "<script>alert('Data Terupdate');document.location.href='k_user.php';</script>";
  27.     }else{
  28.         echo "<script>alert('Data Gagal Terupdate ');document.location.href='k_user.php';</script>";
  29.     }
  30. }
  31. ?>
  32. <html>
  33. <head><title>Form Kelola User</title></head>
  34. <form method="post">
  35.     <table border=1>
  36.         <tr>
  37.             <td>ID</td>
  38.             <td>:</td>
  39.             <td><input type="text" name="kode_user" disabled="true" value="<?php echo @$edit[0] ?>"></td>
  40.         </tr>
  41.         <tr>
  42.                 <tr>
  43.             <td>Username</td>
  44.             <td>:</td>
  45.             <td><input type="text" name="username" value="<?php echo @$edit[1] ?>"></td>
  46.         </tr>
  47.                 <tr>
  48.             <td>Password</td>
  49.             <td>:</td>
  50.             <td><input type="text" name="password" value="<?php echo @$edit[2] ?>"></td>
  51.         </tr>
  52.         <tr>
  53.             <td colspan="2"></td>
  54.             <td>
  55.             <?php if(isset($_GET['edit'])){ ?>
  56.             <input type="submit" name="update" value="Update">
  57.             <?php }else{ ?>
  58.             <input type="submit" name="simpan" value="Simpan">
  59.             <?php } ?>
  60.             <input type="submit" name="kembali" value="Logout">
  61.             </td>
  62.         </tr>
  63.     <table border=1>
  64.         <tr>
  65. <input type="text" name="tcari" value=<?php echo @$_POST['tcari'] ?>>
  66. <input type="submit" name="cari" value="Cari">
  67. <input type="submit" name="R" value="Reset">
  68.             <td>No</td>
  69.             <td>ID</td>
  70.             <td>Username</td>
  71.             <td>Password</td>
  72.             <td>Aksi</td>
  73.         </tr>
  74.         <?php
  75.         $sql="select * from user";
  76.         if(isset($_POST['cari'])){
  77.             $sql="select * from user where nama like'%$_POST[tcari]%'";
  78.         }
  79.         if(isset($_POST['R'])){
  80.             $sql="select * from user";
  81.             echo "<script>document.location.href='k_user.php';</script>";
  82.         }
  83.         $qry=mysqli_query($con,$sql);
  84.         $no=0;
  85.         while($data=mysqli_fetch_array($qry)){
  86.             $no++;
  87.         ?>
  88.         <tr>
  89.             <td><?php echo $no ?></td>
  90.             <td><?php echo $data[0] ?></td>
  91.             <td><?php echo $data[1] ?></td>
  92.             <td><?php echo $data[2] ?></td>
  93.             <td><a href="k_user.php?hapus&id=<?php echo $data[0] ?>">Hapus</a> || <a href="k_user.php?edit&id=<?php echo $data[0] ?>">Edit</a></td>
  94.         </tr>
  95.         <?php } ?>
  96.                    
  97. </form>
  98. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement