WorseG

Untitled

Jan 31st, 2019
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. date_default_timezone_set("Asia/Jakarta");
  4.  
  5. include "config/koneksi.php";
  6.  
  7. if(isset($_GET['hapus'])){
  8.     $hapus="delete from gallery where id_foto='$_GET[id]'";
  9.     $war=mysqli_query($con,$hapus);
  10.     if($war){
  11.         echo "<script>alert('Data Terhapus')</script>";
  12.         echo "<script>document.location.href='index.php';</script>";
  13.     }
  14. }
  15.  
  16. // if (isset($_GET['edit'])) {
  17. //      $et = "SELECT * FROM gallery WHERE id_foto = '$_GET[id]'";
  18. //      $it = mysqli_query($con,$et);
  19. //      $edit = mysqli_fetch_array($it);
  20. //  }
  21.  
  22. // if(isset($_POST['update'])){
  23. //  $tmp = $_FILES['foto']['tmp_name'];
  24. //  $nama_file = $_FILES['foto']['name'];
  25. //  $folder = "foto";
  26.  
  27. //  move_uploaded_file($tmp,"$folder/$nama_file");
  28.  
  29. //  $tgl= date('Y-m-d H:i:s');
  30. //  $pnj="update gallery set judul='$_POST[judul],'foto='$nama_file',tanggal_edit='$tgl' WHERE id_foto = '$_POST[id_foto]'";
  31. //  $ganti = mysqli_query($con,$pnj);
  32. //  if($ganti){
  33. //      echo "<script>alert('Data Teredit')</script>";
  34. //      echo "<script>document.location.href='index.php';</script>";
  35.  
  36. //  }
  37. // }
  38.  
  39.  
  40.  
  41. if(isset($_POST['simpan'])){
  42.     $tmp = $_FILES['foto']['tmp_name'];
  43.     $nama_file = $_FILES['foto']['name'];
  44.     $folder = "foto";
  45.    
  46.     move_uploaded_file($tmp,"$folder/$nama_file");
  47.    
  48.     $tgl = date('Y-m-d H:i:s');
  49.     $simpan = mysqli_query($con,"insert into gallery values (null,'$_POST[judul]','$nama_file','$tgl',null)");
  50.     if($simpan){
  51.         echo "<script>alert('Data Tersimpan')</script>";
  52.         echo "<script>document.location.href='index.php';</script>";
  53.     }
  54. }
  55.  
  56.  ?>
  57. <form method="post" enctype="multipart/form-data">
  58.     <table border="2">
  59. <!--        <tr>
  60.             <td></td>
  61.             <td><td>
  62.             <td><input type="text" name="id_foto" disabled value="<?php echo @$edit[0] ?>"></td>
  63.         </tr> -->
  64.         <tr>
  65.             <td>Judul</td>
  66.             <td>:<td>
  67.             <td><input type="text" name="judul" value="<?php echo @$edit[1] ?>"></td>
  68.         </tr>
  69.         <tr>
  70.             <td>Foto</td>
  71.             <td>:<td>
  72.             <td><input type="file" name="foto" value="<?php echo @$edit[2] ?>"></td>
  73.         </tr>
  74.         <tr>
  75.             <td><input type="submit" name="simpan" value="Simpan"></td>
  76. <!--            <td></td>
  77.             <td><td>
  78.             <td>
  79.             <?php if(isset($_GET['edit'])){ ?>
  80.             <input type="submit" name="update" value="Update">
  81.             <?php }else{ ?>
  82.             <input type="submit" name="simpan" value="Simpan">
  83.              <?php } ?>
  84.             </td></td></td> -->
  85.         </tr>
  86.     </table>
  87. </form>
  88.     <table border="1">
  89.         <tr>
  90.  
  91.             <th>Judul</th>
  92.             <th>Foto</th>
  93.             <th>Tanggal Upload</th>
  94.             <!-- <th>Tanggal Edit</th> -->
  95.             <th>Aksi</th>
  96.         </tr>
  97.             <?php
  98.         $sql="select * from gallery";
  99.         $qry=mysqli_query($con,$sql);
  100.         while($data=mysqli_fetch_array($qry)){
  101.         ?>
  102.         <tr>
  103.  
  104.             <th><?php echo $data[1] ?></th>
  105.             <th><img src="foto/<?php echo $data[2] ?>" width="150" height="100" /></th>
  106.             <th><?php echo $data[3] ?></th>
  107.             <!-- <th><?php echo $data[4] ?></th> -->
  108.             <th><a href="index.php?hapus&id=<?php echo $data[0] ?>">Hapus</a><!--   ||  
  109.                 <a href="index.php?edit&id=<?php echo $data[0] ?>">Edit</a></th> -->
  110.         <?php } ?>
  111.     </table>
RAW Paste Data