Advertisement
Coby_CS

Minta Bantuannya Mas Gan..(fungsi Delete dan Unlink)

May 28th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.69 KB | None | 0 0
  1. // File Add_produk.php
  2. <?php
  3. include 'koneksi.php';
  4. if(cek_login($mysqli) == false){ // Jika user tidak login
  5.     header('location: login.php'); // Alihkan ke halaman login (index.php)
  6.     exit();
  7. }
  8.  
  9. $stmt = $mysqli->prepare("SELECT username FROM user WHERE id = ?");
  10. $stmt->bind_param('i', $_SESSION['id']);
  11. $stmt->execute();
  12. $stmt->store_result();
  13. $stmt->bind_result($username);
  14. $stmt->fetch();
  15. ?>
  16. <?php
  17.                                 if (isset($_POST["simpan"])){
  18.                                 $dir = "upload/";
  19.                                 $lok_file = $_FILES['foto']['tmp_name'];
  20.                                 $nama_file = $_FILES['foto']['name'];
  21.                                 $ekstensi = pathinfo( $nama_file, PATHINFO_EXTENSION );
  22.                                  
  23.                                 $accept = array('jpg','jpeg','png');
  24.                                  
  25.                                 if ( in_array( $ekstensi, $accept ) ) {
  26.                                 $nama_file_modif = "foto-". date('d-m-Y') ."-" . time() . "." . $ekstensi;
  27.                                 $dir_up = $dir .$nama_file_modif;
  28.                                  
  29.                                 move_uploaded_file($lok_file, $dir_up);
  30.                                 $mysqli->query("INSERT INTO produk VALUES('','$_POST[kode_produk]','$_POST[namabarang]','$_POST[harga]','$_POST[deskripsi]','$nama_file_modif','$time()')");
  31.                                             echo '<div class="alert alert-success">Produk telah di postingkan.</div>';
  32.                                             echo "<script>setTimeout(\"location.href='home_admin.php';\",1000);</script>";
  33.                                              
  34.                                             } else {
  35.                                             echo "<p class='alert-error'><b>Gagal...!</b> Pastikan file yang anda upload bertipe jpg/jpeg atau png.</p>
  36.                                             <script>setTimeout(\"self.history.back();\",3000);</script>";
  37.                                             }
  38.                                     }
  39.                                 ?>
  40. <div class="row">
  41.     <div class="col-md- column">
  42.                 <form method="post" class="form-horizontal" action='' enctype="multipart/form-data">
  43.                                 <fieldset>
  44.                                
  45.                                 <!-- Form Name -->
  46.                                
  47.                                 <!-- Text input-->
  48.                                 <div class="form-group">
  49.                                   <label class="col-md-3 control-label" for="Kode Produk">Kode Barang</label>  
  50.                                   <div class="col-md-8">
  51.                                   <input id="Kode Produk" name="kode_produk" placeholder="Kode Produk" class="form-control input-md" type="text">
  52.                                    
  53.                                   </div>
  54.                                 </div>
  55.                                
  56.                                 <!-- Text input-->
  57.                                 <div class="form-group">
  58.                                   <label class="col-md-3 control-label" for="namabarang">Nama Produk</label>  
  59.                                   <div class="col-md-8">
  60.                                   <input id="namabarang" name="namabarang" placeholder="Nama Produk" class="form-control input-md" type="text">
  61.                                    
  62.                                   </div>
  63.                                 </div>
  64.                                
  65.                                 <!-- Prepended text-->
  66.                                 <div class="form-group">
  67.                                   <label class="col-md-3 control-label" for="harga">Harga</label>
  68.                                   <div class="col-md-8">
  69.                                     <div class="input-group">
  70.                                       <span class="input-group-addon">Rp.</span>
  71.                                       <input id="harga" name="harga" class="form-control" placeholder="" type="text">
  72.                                     </div>
  73.                                    
  74.                                   </div>
  75.                                 </div>
  76.                                
  77.                                 <!-- Textarea -->
  78.                                 <div class="form-group">
  79.                                   <label class="col-md-3 control-label" for="deskripsi">Deskirpsi</label>
  80.                                   <div class="col-md-8">
  81.                                     <script type="text/javascript" src="tinymce/tinymce.min.js"></script>
  82.                                     <script type="text/javascript">
  83.                                         tinymce.init({
  84.                                         selector: "textarea"
  85.                                         });
  86.                                     </script>                    
  87.                                     <textarea class="form-control" id="deskripsi" name="deskripsi"></textarea>
  88.                                   </div>
  89.                                 </div>
  90.                                
  91.                                 <!-- File Button -->
  92.                                 <div class="form-group">
  93.                                   <label class="col-md-3 control-label" for="gambar">Pilih Gambar</label>
  94.                                   <div class="col-md-8">
  95.                                     <script type="text/javascript" src="js/bootstrap-filestyle.js"></script>
  96.                                     <input type="file" name="foto" class="filestyle" data-buttonName="btn-danger">
  97.                                     <script type="text/javascript" charset="utf-8">
  98.                                           $(":file").filestyle({buttonName: "btn-danger"});
  99.                                       </script>
  100.                                    
  101.                                   </div>
  102.                                 </div>
  103.                                
  104.                                 <!-- Button (Double) -->
  105.                                 <div class="form-group">
  106.                                   <label class="col-md-4 control-label" for="simpan"></label>
  107.                                   <div class="col-md-4">
  108.                                     <button id="simpan" type="submit"name="simpan" class="btn btn-primary">Posting</button>
  109.                                     <button id="Batal" name="Batal" class="btn btn-danger">Cancel</button>
  110.                                   </div>
  111.                                 </div>
  112.                                 </fieldset>
  113.                                 </form>
  114.                                
  115.             </div>
  116. </div>
  117.  
  118. // sintak Delete.php
  119.  
  120. <?php
  121. include 'koneksi.php';
  122.     $del = $mysqli->query("DELETE FROM produk where id='$_GET[id]'");
  123.    
  124.     if(isset($_GET['foto'])){
  125.     $idfoto=$_GET['foto'];
  126.     $file="upload/".$idfoto;
  127.     unlink("$idfoto");
  128.     header( 'Location:home_admin.php' ) ;
  129.            
  130.     }
  131.    
  132. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement