Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File Add_produk.php
- <?php
- include 'koneksi.php';
- if(cek_login($mysqli) == false){ // Jika user tidak login
- header('location: login.php'); // Alihkan ke halaman login (index.php)
- exit();
- }
- $stmt = $mysqli->prepare("SELECT username FROM user WHERE id = ?");
- $stmt->bind_param('i', $_SESSION['id']);
- $stmt->execute();
- $stmt->store_result();
- $stmt->bind_result($username);
- $stmt->fetch();
- ?>
- <?php
- if (isset($_POST["simpan"])){
- $dir = "upload/";
- $lok_file = $_FILES['foto']['tmp_name'];
- $nama_file = $_FILES['foto']['name'];
- $ekstensi = pathinfo( $nama_file, PATHINFO_EXTENSION );
- $accept = array('jpg','jpeg','png');
- if ( in_array( $ekstensi, $accept ) ) {
- $nama_file_modif = "foto-". date('d-m-Y') ."-" . time() . "." . $ekstensi;
- $dir_up = $dir .$nama_file_modif;
- move_uploaded_file($lok_file, $dir_up);
- $mysqli->query("INSERT INTO produk VALUES('','$_POST[kode_produk]','$_POST[namabarang]','$_POST[harga]','$_POST[deskripsi]','$nama_file_modif','$time()')");
- echo '<div class="alert alert-success">Produk telah di postingkan.</div>';
- echo "<script>setTimeout(\"location.href='home_admin.php';\",1000);</script>";
- } else {
- echo "<p class='alert-error'><b>Gagal...!</b> Pastikan file yang anda upload bertipe jpg/jpeg atau png.</p>
- <script>setTimeout(\"self.history.back();\",3000);</script>";
- }
- }
- ?>
- <div class="row">
- <div class="col-md- column">
- <form method="post" class="form-horizontal" action='' enctype="multipart/form-data">
- <fieldset>
- <!-- Form Name -->
- <!-- Text input-->
- <div class="form-group">
- <label class="col-md-3 control-label" for="Kode Produk">Kode Barang</label>
- <div class="col-md-8">
- <input id="Kode Produk" name="kode_produk" placeholder="Kode Produk" class="form-control input-md" type="text">
- </div>
- </div>
- <!-- Text input-->
- <div class="form-group">
- <label class="col-md-3 control-label" for="namabarang">Nama Produk</label>
- <div class="col-md-8">
- <input id="namabarang" name="namabarang" placeholder="Nama Produk" class="form-control input-md" type="text">
- </div>
- </div>
- <!-- Prepended text-->
- <div class="form-group">
- <label class="col-md-3 control-label" for="harga">Harga</label>
- <div class="col-md-8">
- <div class="input-group">
- <span class="input-group-addon">Rp.</span>
- <input id="harga" name="harga" class="form-control" placeholder="" type="text">
- </div>
- </div>
- </div>
- <!-- Textarea -->
- <div class="form-group">
- <label class="col-md-3 control-label" for="deskripsi">Deskirpsi</label>
- <div class="col-md-8">
- <script type="text/javascript" src="tinymce/tinymce.min.js"></script>
- <script type="text/javascript">
- tinymce.init({
- selector: "textarea"
- });
- </script>
- <textarea class="form-control" id="deskripsi" name="deskripsi"></textarea>
- </div>
- </div>
- <!-- File Button -->
- <div class="form-group">
- <label class="col-md-3 control-label" for="gambar">Pilih Gambar</label>
- <div class="col-md-8">
- <script type="text/javascript" src="js/bootstrap-filestyle.js"></script>
- <input type="file" name="foto" class="filestyle" data-buttonName="btn-danger">
- <script type="text/javascript" charset="utf-8">
- $(":file").filestyle({buttonName: "btn-danger"});
- </script>
- </div>
- </div>
- <!-- Button (Double) -->
- <div class="form-group">
- <label class="col-md-4 control-label" for="simpan"></label>
- <div class="col-md-4">
- <button id="simpan" type="submit"name="simpan" class="btn btn-primary">Posting</button>
- <button id="Batal" name="Batal" class="btn btn-danger">Cancel</button>
- </div>
- </div>
- </fieldset>
- </form>
- </div>
- </div>
- // sintak Delete.php
- <?php
- include 'koneksi.php';
- $del = $mysqli->query("DELETE FROM produk where id='$_GET[id]'");
- if(isset($_GET['foto'])){
- $idfoto=$_GET['foto'];
- $file="upload/".$idfoto;
- unlink("$idfoto");
- header( 'Location:home_admin.php' ) ;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement