Online Course

ISN07 - Tutorial Membuat Pengelolaan Data Produk DI Halaman Admin

Tutorial Membuat Pengelolaan Data Produk DI Halaman Admin

Ikuti langkah berikut ini

Pertama, Buat tabel baru dengan nama tb_produk di database

struktur dari tb_produk seperti ini

tb_produk

Kedua, Buat file baru dengan nama produk.php simpan di folder ADMINWEB

isi dari file produk.php seperti ini

<?php
//pemanggilan file metatag
include "setting_metatag.php";

//pemanggilan file navbar
include "setting_navbar.php";
?>

        <div id="page-wrapper">

            <div class="container-fluid">
                <!-- .row -->
                <!-- Page Heading  breadcumb-->
                <div class="row">
                    <div class="col-lg-12">
                        <h3>
                            Data Produk
                            <a href="input_produk.php" title="Input data"><button name="input" class="btn btn-primary pull-right"><i class="fa fa-plus fa-fw"></i> Tambah Produk</button></a>

                        </h3>
                        <ol class="breadcrumb">
                            <li class="active">
                                <i class="fa fa-dashboard"></i> Home
                            </li>
                            <li class="active">
                                <i class="fa fa-list"></i> Data Produk
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->

                <!-- .row -->
                <div class="row">

                <!-- .col lg 12 -->
                    <div class="col-lg-12">

                    <!-- panel . (Pelajari cara membuat panel di bootstrap yah)-->
                        <div class="panel panel-default">

                        <!-- panel heading -->
                            <div class="panel-heading">
                            <div class="col-lg-6">
                            Daftar produk
                            </div>
                            <div class="col-lg-6">
                            <!-- form pencarian produk -->
                            <form action="cari_produk.php" method="get" class="form-inline text-right">
                            <input type="text" class="form-control" name="qw" placeholder="Cari Produk" required>
                            <button type="submit" class="btn btn-primary">Cari</button>
                            </form>
                            <!-- form pencarian produk -->
                            </div>
                            <div style="clear:both;"></div>
                            </div>
                        <!-- /.panel heading -->

                        <!-- panel body -->
                            <div class="panel-body">

                            <!-- /.tabel responsive -->
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover table-striped">
                                        <thead>
                                            <tr>
                                                <th>No</th>
                                                <th>Nama Produk</th>
                                                <th>Harga</th>
                                                <th>Gambar</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <?php
                                        $pg = isset( $_GET['pg'] ) ? $_GET['pg'] : "";
                                        $batas = 10; /*batas tampilan setiap halaman*/
                                        if ( empty( $pg ) ) {
                                        $posisi = 0;
                                        $pg = 1;
                                        } else {
                                        $posisi = ( $pg - 1 ) * $batas;
                                        }
                                        /*Jika variabel $pg kosong maka akan menampilkan halaman pertama dengan batas baris 10*/

                                        $ambildata=mysqli_query($conect, "select*from tb_produk, tb_kategori where tb_produk.id_kategori=tb_kategori.id_kategori order by id_produk desc limit $posisi, $batas");
                                        $jumlah=mysqli_num_rows($ambildata);  /*mysql_num_rows untuk menghitung total baris di tabel databse*/
                                        if($jumlah == 0){  //jika tidak ada data
                                            ?>
                                        <tr>
                                            <td colspan="11">Tidak Terdapat Data</td>
                                        </tr>
                                        <?php
                                        }else{
                                        //jika ada data di tb_brand
                                        while($a=mysqli_fetch_array($ambildata)){ /*mysql_fetch array untuk mengambil data di setiap field di tabel databse*/
                                        ?>
                                        <tr>
                                            <td><?php echo $posisi=$posisi+1;?></td>
                                            <td><b><?php echo $a['nama_produk'];?></b>
                                            <br>Kategori : <?php echo $a['nama_kategori'];?>
                                            <br>Berat : <?php echo $a['berat_produk'];?> gr
                                            <br>Stok : <?php echo $a['stok_produk'];?>%
                                            <br>Diskon : <?php echo $a['diskon_produk'];?>%
                                            <br>Terjual : <?php echo $a['terjual'];?>
                                            </td>
                                            <td>Min. <?php echo $a['min_pembelian'];?> Harga /item : <?php echo number_format($a['harga_produk']);?>
                                            <?php
                                            if($a['min_order1'] != 0){
                                                ?>
                                            <br>Min. <?php echo $a['min_order1'];?> Harga / item : <?php echo number_format($a['harga_order1']);?>
                                            <?php
                                            }
                                            if($a['min_order2'] != 0){
                                                ?>
                                            <br>Min. <?php echo $a['min_order2'];?> Harga / item : <?php echo number_format($a['harga_order2']);?>
                                            <?php
                                            }
                                            if($a['min_order3'] != 0){
                                                ?>
                                            <br>Min. <?php echo $a['min_order3'];?> Harga / item : <?php echo number_format($a['harga_order3']);?>
                                            <?php
                                            }
                                            ?>
                                            </td>
                                            <td><img src="<?php echo $hostname;?>/assets/images/produk/<?php echo $a['gambar_produk'];?>" class="img-thumbnail" style="width:100px; height:100px;"></td>
                                            <td><a href="hapus_produk.php?id_produk=<?php echo $a['id_produk'];?>" onclick="return confirm('Yakin akan meghapus data ini')" title="Hapus data"><button class="btn btn-danger btn-sm"><i class="fa fa-trash-o fa-fw"></i> Hapus</button></a>
                                            <a href="edit_produk.php?id_produk=<?php echo $a['id_produk'];?>" title="Edit data"><button class="btn btn-primary btn-sm"><i class="fa fa-pencil-square-o fa-fw"></i> Edit</button> </a>
                                            </td>
                                        </tr>
                                        <?php
                                            }
                                        }
                                        ?>
                                        </tbody>
                                    </table>
                                </div>
                                <!-- /.tabel responsive -->

                                <div class="text-center">
                                    <?php
                                //script paging, untuk menampikan setiap halaman
                                $jml_data = mysqli_num_rows(mysqli_query($conect, "select*from tb_produk, tb_kategori where tb_produk.id_kategori=tb_kategori.id_kategori order by id_produk desc"));
                                $JmlHalaman = ceil($jml_data/$batas); //ceil digunakan untuk pembulatan keatas
                                if($jml_data != 0){
                                if ( $pg > 1 ) {
                                $link = $pg-1;
                                $prev = "<a href='?pg=$link'><button name='prev' class='btn btn-primary btn-sm'>Prev</button></a> ";
                                } else {
                                $prev = "<button name='prev' class='btn btn-default btn-sm'>Prev </button> ";
                                }
                                $nmr = '';
                                for ( $i = 1; $i<= $JmlHalaman; $i++ ){

                                if ( $i == $pg ) {
                                $nmr .= "<button name='prev' class='btn btn-primary btn-sm'>$i</button> ";
                                } else {
                                $nmr .= "<a href='?pg=$i'><button name='prev' class='btn btn-default btn-sm'>$i</button></a> ";
                                }
                                }
                                if ( $pg < $JmlHalaman ) {
                                $link = $pg + 1;
                                $next = "<a href='?pg=$link'><button name='prev' class='btn btn-primary btn-sm'>Next</button></a> ";
                                } else {
                                $next = "<button name='prev' class='btn btn-default btn-sm'>Next</button> ";
                                }
                                echo $prev.$nmr.$next;
                                ?>
                                <br><br>
                                <span class="text-muted">Menampilkan <?php echo $jumlah; ?> dari <?php echo $jml_data; ?> Record </span>
                                <?php
                                }
                                ?>
                                </div>
                            </div>
                            <!-- /.panel body -->

                        </div>
                        <!-- /.panel -->

                    </div>
                    <!-- /.col lg 12-->

                </div>
                <!-- /.row -->


           </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

<?php
//pemanggilan file setting footer
include "setting_footer.php";

?>

Hasil dari file produk.php akan menampilkan seperti ini

daftar-produk

Ketiga, Buat file baru dengan nama input_produk.php simpan di folder ADMINWEB

isi dari file input_produk.php seperti ini

<?php
//pemanggilan file metatag
include "setting_metatag.php";

//pemanggilan file navbar
include "setting_navbar.php";
?>

        <div id="page-wrapper">

            <div class="container-fluid">
                <!-- .row -->
                <!-- Page Heading  breadcumb-->
                <div class="row">
                    <div class="col-lg-12">
                        <h3>
                            Tambah Produk Baru
                        </h3>
                        <ol class="breadcrumb">
                            <li class="active">
                                <i class="fa fa-dashboard"></i> Home
                            </li>
                            <li class="active">
                                <i class="fa fa-list"></i> Tambah Produk
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->

                <?php
                //variabel setiap input di form
                $nama=mysqli_real_escape_string($conect, $_POST['nama']);  //variabel dari name input nama
                $kategori=mysqli_real_escape_string($conect, $_POST['kategori']);     //variabel dari name input kategori
                $brand=mysqli_real_escape_string($conect, $_POST['brand']);     //variabel dari name input brand
                $supplier=mysqli_real_escape_string($conect, $_POST['supplier']);     //variabel dari name input supplier
                $deskripsi=mysqli_real_escape_string($conect, $_POST['deskripsi']);     //variabel dari name input deskripsi
                $stok=mysqli_real_escape_string($conect, $_POST['stok']);     //variabel dari name input stok
                $harga=mysqli_real_escape_string($conect, $_POST['harga']);     //variabel dari name input harga
                $diskon=mysqli_real_escape_string($conect, $_POST['diskon']);     //variabel dari name input diskon
                $berat=mysqli_real_escape_string($conect, $_POST['berat']);     //variabel dari name input berat
                $min1=mysqli_real_escape_string($conect, $_POST['min1']);
                $min2=mysqli_real_escape_string($conect, $_POST['min2']);
                $min3=mysqli_real_escape_string($conect, $_POST['min3']);
                $hg1=mysqli_real_escape_string($conect, $_POST['hg1']);
                $hg2=mysqli_real_escape_string($conect, $_POST['hg2']);
                $hg3=mysqli_real_escape_string($conect, $_POST['hg3']);
                $min_pem=mysqli_real_escape_string($conect, $_POST['min_pembelian']);


                $foto=$_FILES['foto']['tmp_name'];               //variabel dari temporary foto
                $nama_foto=$_FILES ['foto']['name'];             //variabel dari name input foto
                $type=$_FILES['foto']['type'];                   //variabel dari type foto
                $ukuran=$_FILES['foto']['size'];                 //variabel dari ukuran foto
                $files= strtolower(substr(strrchr($nama_foto,"."),1)); //variabel untuk extensi file

                //jika menekan tombol simpan
                if(isset($_POST['simpan'])){
                if(empty($nama)){  //jika field nama kosong
                $er_nama="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Nama Produk </div>";
                }
                elseif(empty($kategori)){ //jika field kategori kosong
                $er_kategori="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Pilih Kategori Produk</div>";
                }
                elseif(empty($deskripsi)){ //jika field deskripsi kosong
                $er_deskripsi="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Deskripsi Produk</div>";
                }
                elseif(empty($harga)){ //jika field harga kosong
                $er_harga="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Harga Produk</div>";
                }
                elseif(empty($stok)){ //jika field stok kosong
                $er_stok="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Stok Produk</div>";
                }
                elseif(empty($berat)){ //jika field berat kosong
                $er_berat="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Berat Produk</div>";
                }
                elseif(empty($foto)){  //jika foto kosong
                $er_foto="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Foto Produk</div>";
                }
                elseif($files !="jpg" && $files !="png"){ //jika foto tidak berekstensi .jpg atau .png
                $er_foto="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Format Gambar yang diizinkan hanya .jpg dan .png</div>";
                }
                elseif($ukuran > 2000000){   //jika ukuran lebih besar dari 2MB
                $er_foto="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Maksimal ukuran gambar 2MB </div>";
                }
                elseif(strlen($nama_foto) > 100){  //jika jumlah karakter nama foto lebih dari 100 karakter
                $er_foto="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Nama File Gambar Mak 100 karakter</div>";
                }
                else{ //jika semua field terpenuhi maka smpan gambar ke folder produk dan simpan data ke tb_produk
                move_uploaded_file($foto,"../assets/images/produk/$nama_foto");
                $save=mysqli_query($conect, "INSERT INTO tb_produk (id_produk,nama_produk,id_kategori,diskon_produk,berat_produk,harga_produk,stok_produk,gambar_produk,deskripsi_produk,min_order1,harga_order1,min_order2,harga_order2,min_order3,harga_order3,min_pembelian)
                values('','$nama','$kategori','$diskon','$berat','$harga','$stok','$nama_foto','$deskripsi','$min1','$hg1','$min2','$hg2','$min3','$hg3','$min_pem')") or die(mysqli_error($conect));
                if($save){ //jika simpan berhasil
                echo "<script>alert('Data Berhasil Disimpan');document.location='produk.php'</script>";
                }
                else{  //jika simpan gagal
                $error="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Error</div>";
                }

                }
                }
                ?>
                <!-- .row -->
                <div class="row">

                <!-- .col lg 12 -->
                    <div class="col-lg-12">

                    <!-- panel . (Pelajari cara membuat panel di bootstrap yah)-->
                        <div class="panel panel-default">

                        <!-- panel heading -->
                            <div class="panel-heading">
                                <h3 class="panel-title">
                                <a href="produk.php" title="Input data"><button name="input" class="btn btn-primary">Kembali</button></a>
                                </h3>
                            </div>
                        <!-- /.panel heading -->

                        <!-- panel body -->
                            <div class="panel-body">

                            <!-- /.form menggunakan form group, pelajari cara membuat form di bootstrap-->

                            <form action="" method="post" enctype="multipart/form-data" role="form">
                            <?php echo $error;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Nama Produk</label>
                                <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12">
                                <input type="text" class="form-control" placeholder="Nama Produk" name="nama" value="<?php echo $_POST['nama'];?>" maxlength="100">
                                </div>
                            </div>
                            <?php echo $er_nama;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Kategori Produk</label>
                                <div class="col-lg-5 col-md-5 col-sm-5 col-xs-12">
                                <select name="kategori" class="form-control">
                                        <option value="">Pilih Kategori Produk</option>
                                        <?php $kategori=mysqli_query($conect, "select *from tb_kategori");
                                        while($q=mysqli_fetch_array($kategori)){
                                        if($q['id_kategori']== $_POST['kategori']){
                                        echo "
                                        <option value='$q[id_kategori]' selected>$q[nama_kategori]</option>";
                                        }
                                        else{
                                        echo "
                                        <option value='$q[id_kategori]'>$q[nama_kategori]</option>";
                                        }

                                        }
                                        ?> </select>
                                        </div>
                            </div>
                            <?php echo $er_kategori;?>

                            <div class="form-group row">
                                 <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Deskripsi Produk</label>
                                   <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12">
                                   <textarea name="deskripsi" class="form-control" id="editor1" rows="5" placeholder="Deskripsi Produk"><?php echo $_POST['deskripsi'];?></textarea>
                                   </div>
                            </div>
                            <?php echo $er_deskripsi;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Min. Pembelian</label>
                                <div class="col-lg-3 col-md-5 col-sm-5 col-xs-12">
                                <input type="number" class="form-control" placeholder="Min. Pembelian" name="min_pembelian" value="<?php echo $_POST['min_pembelian'];?>" maxlength="10000">
                                <small class="text-muted">Minimal Pembelian 1 item dan maksimal 10.000 item</small>
                                </div>
                            </div>
                            <?php echo $er_minpem;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Harga / Item</label>
                                <div class="col-lg-7 col-md-5 col-sm-5 col-xs-12">
                                     <div class="input-group"><span class="input-group-addon">Rp.</span>
                                     <input type="text" class="form-control" placeholder="Harga Produk" name="harga" value="<?php echo $_POST['harga'];?>" maxlength="100">
                                     </div>
                                     <br>
                                     <div class="col-lg-3">
                                     <label>Min.Order</label>
                                     <div class="input-group"><span class="input-group-addon">></span>
                                     <input type="text" class="form-control" name="min1" value="<?php echo $_POST['min1'];?>">
                                     </div>
                                     
                                     </div>
                                     
                                     <div class="col-lg-4">
                                     <label>Harga Grosir</label>
                                     <div class="input-group"><span class="input-group-addon">=</span>
                                     <input type="text" class="form-control" name="hg1" value="<?php echo $_POST['hg1'];?>">
                                     </div>
                                     
                                     </div>
                                     <div class="clearfix"></div>
                                     <div class="col-lg-3">
                                     <label>Min.Order</label>
                                     <div class="input-group"><span class="input-group-addon">></span>
                                     <input type="text" class="form-control" name="min2" value="<?php echo $_POST['min2'];?>">
                                     </div>

                                     </div>

                                     <div class="col-lg-4">
                                     <label>Harga Grosir</label>
                                     <div class="input-group"><span class="input-group-addon">=</span>
                                     <input type="text" class="form-control" name="hg2" value="<?php echo $_POST['hg2'];?>">
                                     </div>

                                     </div>
                                     
                                     <div class="clearfix"></div>
                                     <div class="col-lg-3">
                                     <label>Min.Order</label>
                                     <div class="input-group"><span class="input-group-addon">></span>
                                     <input type="text" class="form-control" name="min3" value="<?php echo $_POST['min3'];?>">
                                     </div>

                                     </div>

                                     <div class="col-lg-4">
                                     <label>Harga Grosir</label>
                                     <div class="input-group"><span class="input-group-addon">=</span>
                                     <input type="text" class="form-control" name="hg3" value="<?php echo $_POST['hg3'];?>">
                                     </div>

                                     </div>
                                     
                                </div>
                            </div>
                            <?php echo $er_harga;?>

                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Stok Produk</label>
                                <div class="col-lg-4 col-md-3 col-sm-3 col-xs-12">
                                <div class="input-group">
                                <input type="text" class="form-control" placeholder="Stok Produk" name="stok" value="<?php echo $_POST['stok'];?>" maxlength="100">
                                <span class="input-group-addon">item</span></div>
                                </div>
                            </div>
                            <?php echo $er_stok;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Berat Produk (gram)</label>
                                <div class="col-lg-4 col-md-3 col-sm-3 col-xs-12">
                                <div class="input-group">
                                <input type="text" class="form-control" placeholder="Berat Produk dalam gram" name="berat" value="<?php echo $_POST['berat'];?>" maxlength="100">
                                <span class="input-group-addon">gram</span></div>
                                </div>
                            </div>
                            <?php echo $er_berat;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Diskon Produk</label>
                                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
                                <div class="input-group">
                                <input type="number" class="form-control" placeholder="Diskon Produk" name="diskon" value="<?php echo $_POST['diskon'];?>" maxlength="3">
                                <span class="input-group-addon">%</span></div>
                                </div>
                            </div>
                            <?php echo $er_diskon;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Gambar Produk</label>
                                <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12">
                                <input type="file" class="form-control-file" name="foto" accept=".jpg, .png">
                                </div>
                            </div>
                            <?php echo $er_foto;?>
                            <hr>
                            <button type="submit" name="simpan" class="btn btn-success">Simpan</button>

                            </form>
                                <!-- /.form -->

                            </div>
                            <!-- /.panel body -->

                        </div>
                        <!-- /.panel -->

                    </div>
                    <!-- /.col lg 12-->

                </div>
                <!-- /.row -->


           </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

<?php
//pemanggilan file setting footer
include "setting_footer.php";

?>

Hasil dari file input_produk.php akan menampilkan seperti ini

input-produk

Keempat, Buat file baru dengan nama edit_produk.php simpan di folder ADMINWEB

isi dari file edit_produk.php seperti ini

<?php
//pemanggilan file metatag
include "setting_metatag.php";

//pemanggilan file navbar
include "setting_navbar.php";
?>

        <div id="page-wrapper">

            <div class="container-fluid">
                <!-- .row -->
                <!-- Page Heading  breadcumb-->
                <div class="row">
                    <div class="col-lg-12">
                        <h3>
                            Perbaharui Data Produk
                        </h3>
                        <ol class="breadcrumb">
                            <li class="active">
                                <i class="fa fa-dashboard"></i> Home
                            </li>
                            <li class="active">
                                <i class="fa fa-list"></i> Data Produk
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->

                <?php
                ///ambil data berdasarkan id
                $tampildata=mysqli_query($conect, "select*from tb_produk where id_produk='$_GET[id_produk]'");
                $b=mysqli_fetch_array($tampildata);

                //variabel setiap input di form

                $lama=$_POST['foto_lama'];  //variabel foto lama
                $nama=mysqli_real_escape_string($conect, $_POST['nama']);  //variabel dari name input nama
                $kategori=mysqli_real_escape_string($conect, $_POST['kategori']);     //variabel dari name input kategori
                $brand=mysqli_real_escape_string($conect, $_POST['brand']);     //variabel dari name input brand
                $supplier=mysqli_real_escape_string($conect, $_POST['supplier']);     //variabel dari name input supplier
                $deskripsi=mysqli_real_escape_string($conect, $_POST['deskripsi']);     //variabel dari name input deskripsi
                $stok=mysqli_real_escape_string($conect, $_POST['stok']);     //variabel dari name input stok
                $harga=mysqli_real_escape_string($conect, $_POST['harga']);     //variabel dari name input harga
                $diskon=mysqli_real_escape_string($conect, $_POST['diskon']);     //variabel dari name input diskon
                $berat=mysqli_real_escape_string($conect, $_POST['berat']);     //variabel dari name input berat
                $min1=mysqli_real_escape_string($conect, $_POST['min1']);
                $min2=mysqli_real_escape_string($conect, $_POST['min2']);
                $min3=mysqli_real_escape_string($conect, $_POST['min3']);
                $hg1=mysqli_real_escape_string($conect, $_POST['hg1']);
                $hg2=mysqli_real_escape_string($conect, $_POST['hg2']);
                $hg3=mysqli_real_escape_string($conect, $_POST['hg3']);
                $min_pem=mysqli_real_escape_string($conect, $_POST['min_pembelian']);

                $foto=$_FILES['foto']['tmp_name'];               //variabel dari temporary foto
                $nama_foto=$_FILES ['foto']['name'];             //variabel dari name input foto
                $type=$_FILES['foto']['type'];                   //variabel dari type foto
                $ukuran=$_FILES['foto']['size'];                 //variabel dari ukuran foto
                $files= strtolower(substr(strrchr($nama_foto,"."),1)); //variabel untuk extensi file

                //jika menekan tombol simpan
                if(isset($_POST['simpan'])){
                if(empty($nama)){  //jika field nama kosong
                $er_nama="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Nama Produk </div>";
                }
                elseif(empty($kategori)){ //jika field kategori kosong
                $er_kategori="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Pilih Kategori Produk</div>";
                }
                elseif(empty($deskripsi)){ //jika field deskripsi kosong
                $er_deskripsi="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Deskripsi Produk</div>";
                }
                elseif(empty($harga)){ //jika field harga kosong
                $er_harga="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Harga Produk</div>";
                }
                elseif(empty($stok)){ //jika field stok kosong
                $er_stok="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Stok Produk</div>";
                }
                elseif(empty($berat)){ //jika field berat kosong
                $er_berat="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Masukan Berat Produk</div>";
                }
                else{
                if(empty($foto)){  //jika foto tidak diubah maka
                $save=mysqli_query($conect, "UPDATE tb_produk set nama_produk='$nama',id_kategori='$kategori',diskon_produk='$diskon',berat_produk='$berat',harga_produk='$harga',stok_produk='$stok',deskripsi_produk='$deskripsi', min_order1='$min1', harga_order1='$hg1', min_order2='$min2', harga_order2='$hg2', min_order3='$min3', harga_order3='$hg3', min_pembelian='$min_pem' where id_produk='$_GET[id_produk]'");
                if($save){ //jika simpan berhasil
                echo "<script>alert('Data Berhasil Diperbaharui');document.location='produk.php'</script>";
                }
                else{  //jika simpan gagal
                $error="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Error</div>";
                }
                }
                else{ //jika foto ikut diubah maka
                if($files !="jpg" && $files !="png"){ //jika foto tidak berekstensi .jpg atau .png
                $er_foto="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Format Gambar yang diizinkan hanya .jpg dan .png</div>";
                }
                elseif($ukuran > 2000000){   //jika ukuran lebih besar dari 2MB
                $er_foto="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Maksimal ukuran gambar 2MB </div>";
                }
                elseif(strlen($nama_foto) > 100){  //jika jumlah karakter nama foto lebih dari 100 karakter
                $er_foto="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Nama File Gambar Mak 100 karakter</div>";
                }
                else{
                unlink('../assets/images/brand/'.$lama); //hapus foto lama di folder
                move_uploaded_file($foto,"../assets/images/produk/$nama_foto"); //upload foto baru
                $save=mysqli_query($conect, "UPDATE tb_produk set nama_produk='$nama',id_kategori='$kategori',diskon_produk='$diskon',berat_produk='$berat',harga_produk='$harga',stok_produk='$stok',gambar_produk='$nama_foto',deskripsi_produk='$deskripsi', min_order1='$min1', harga_order1='$hg1', min_order2='$min2', harga_order2='$hg2', min_order3='$min3', harga_order3='$hg3', min_pembelian='$min_pem' where id_produk='$_GET[id_produk]'");
                if($save){ //jika simpan berhasil
                echo "<script>alert('Data Berhasil Diperbaharui');document.location='produk.php'</script>";
                }
                else{  //jika simpan gagal
                $error="<div class='alert alert-warning alert-dismissable'>
                <button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>
                <i class='fa fa-info-circle'></i> Error</div>";
                }
                }
                }
                }
                }
                ?>
                <!-- .row -->
                <div class="row">

                <!-- .col lg 12 -->
                    <div class="col-lg-12">

                    <!-- panel . (Pelajari cara membuat panel di bootstrap yah)-->
                        <div class="panel panel-default">

                        <!-- panel heading -->
                            <div class="panel-heading">
                                <a href="produk.php" title="Input data"><button name="input" class="btn btn-primary">Kembali</button></a>
                            </div>
                        <!-- /.panel heading -->

                        <!-- panel body -->
                            <div class="panel-body">

                            <!-- /.form menggunakan form group, pelajari cara membuat form di bootstrap-->

                            <form action="" method="post" enctype="multipart/form-data" role="form">
                            <?php echo $error;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Nama Produk</label>
                                <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12">
                                <input type="text" class="form-control" placeholder="Nama Produk" name="nama" value="<?php echo $b['nama_produk'];?>" maxlength="100">
                                </div>
                            </div>
                            <?php echo $er_nama;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Kategori Produk</label>
                                <div class="col-lg-5 col-md-5 col-sm-5 col-xs-12">
                                <select name="kategori" class="form-control">
                                        <option value="">Pilih Kategori Produk</option>
                                        <?php $kategori=mysqli_query($conect, "select *from tb_kategori");
                                        while($q=mysqli_fetch_array($kategori)){
                                        if($q['id_kategori']== $b['id_kategori']){
                                        echo "
                                        <option value='$q[id_kategori]' selected>$q[nama_kategori]</option>";
                                        }
                                        else{
                                        echo "
                                        <option value='$q[id_kategori]'>$q[nama_kategori]</option>";
                                        }

                                        }
                                        ?> </select>
                                        </div>
                            </div>
                            <?php echo $er_kategori;?>

                            <div class="form-group row">
                                 <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Deskripsi Produk</label>
                                   <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12">
                                   <textarea name="deskripsi" class="form-control" id="editor1" rows="5" placeholder="Deskripsi Artikel"><?php echo $b['deskripsi_produk'];?></textarea>
                                   </div>
                            </div>
                            <?php echo $er_deskripsi;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Min. Pembelian</label>
                                <div class="col-lg-3 col-md-5 col-sm-5 col-xs-12">
                                <input type="number" class="form-control" placeholder="Min. Pembelian" name="min_pembelian" value="<?php echo $b['min_pembelian'];?>" maxlength="10000">
                                <small class="text-muted">Minimal Pembelian 1 item dan maksimal 10.000 item</small>
                                </div>
                            </div>
                            <?php echo $er_minpem;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Harga / Item</label>
                                <div class="col-lg-7 col-md-5 col-sm-5 col-xs-12">
                                     <div class="input-group"><span class="input-group-addon">Rp.</span>
                                     <input type="text" class="form-control" placeholder="Harga Produk" name="harga" value="<?php echo $b['harga_produk'];?>" maxlength="100">
                                     </div>
                                     <br>
                                     <div class="col-lg-3">
                                     <label>Min.Order</label>
                                     <div class="input-group"><span class="input-group-addon">></span>
                                     <input type="text" class="form-control" name="min1" value="<?php echo $b['min_order1'];?>">
                                     </div>

                                     </div>

                                     <div class="col-lg-4">
                                     <label>Harga Grosir</label>
                                     <div class="input-group"><span class="input-group-addon">=</span>
                                     <input type="text" class="form-control" name="hg1" value="<?php echo $b['harga_order1'];?>">
                                     </div>

                                     </div>
                                     <div class="clearfix"></div>
                                     <div class="col-lg-3">
                                     <label>Min.Order</label>
                                     <div class="input-group"><span class="input-group-addon">></span>
                                     <input type="text" class="form-control" name="min2" value="<?php echo $b['min_order2'];?>">
                                     </div>

                                     </div>

                                     <div class="col-lg-4">
                                     <label>Harga Grosir</label>
                                     <div class="input-group"><span class="input-group-addon">=</span>
                                     <input type="text" class="form-control" name="hg2" value="<?php echo $b['harga_order2'];?>">
                                     </div>

                                     </div>

                                     <div class="clearfix"></div>
                                     <div class="col-lg-3">
                                     <label>Min.Order</label>
                                     <div class="input-group"><span class="input-group-addon">></span>
                                     <input type="text" class="form-control" name="min3" value="<?php echo $b['min_order3'];?>">
                                     </div>

                                     </div>

                                     <div class="col-lg-4">
                                     <label>Harga Grosir</label>
                                     <div class="input-group"><span class="input-group-addon">=</span>
                                     <input type="text" class="form-control" name="hg3" value="<?php echo $b['harga_order3'];?>">
                                     </div>

                                     </div>

                                </div>
                            </div>
                            <?php echo $er_harga;?>

                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Stok Produk</label>
                                <div class="col-lg-4 col-md-3 col-sm-3 col-xs-12">
                                <div class="input-group">
                                <input type="text" class="form-control" placeholder="Stok Produk" name="stok" value="<?php echo $b['stok_produk'];?>" maxlength="100">
                                <span class="input-group-addon">item</span></div>
                                </div>
                            </div>
                            <?php echo $er_stok;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Berat Produk (gram)</label>
                                <div class="col-lg-4 col-md-3 col-sm-3 col-xs-12">
                                <div class="input-group">
                                <input type="text" class="form-control" placeholder="Berat Produk dalam gram" name="berat" value="<?php echo $b['berat_produk'];?>" maxlength="100">
                                <span class="input-group-addon">gram</span></div>
                                </div>
                            </div>
                            <?php echo $er_berat;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Diskon Produk</label>
                                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
                                <div class="input-group">
                                <input type="number" class="form-control" placeholder="Diskon Produk" name="diskon" value="<?php echo $b['diskon_produk'];?>" maxlength="3">
                                <span class="input-group-addon">%</span></div>
                                </div>
                            </div>
                            <?php echo $er_diskon;?>
                            <div class="form-group row">
                                <label class="col-lg-2 col-md-3 col-sm-3 col-xs-12">Gambar Produk</label>
                                <div class="col-lg-8 col-md-7 col-sm-7 col-xs-12">
                                <input type="file" class="form-control-file" name="foto" accept=".jpg, .png">
                                <input type="hidden" name="foto_lama" value="<?php echo $b['gambar_produk'];?>">
                                </div>
                            </div>
                            <?php echo $er_foto;?>
                            <hr>
                            <button type="submit" name="simpan" class="btn btn-success">Simpan</button>

                            </form>
                                <!-- /.form -->

                            </div>
                            <!-- /.panel body -->

                        </div>
                        <!-- /.panel -->

                    </div>
                    <!-- /.col lg 12-->

                </div>
                <!-- /.row -->


           </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

<?php
//pemanggilan file setting footer
include "setting_footer.php";

?>

Hasil dari file edit_produk.php akan menampilkan seperti ini

edit-produk

Kelima, Buat file baru dengan nama hapus_produk.php simpan di folder ADMINWEB

isi dari file hapus_produk.php seperti ini

<?php
session_start();
//panggil koneksi
include "../assets/relasi/koneksi.php";

$id=$_GET['id_produk'];  //dapatkan id

if(isset($id)){ //jika ada id
//ambil data di tabel berdasarkan id
$data=mysqli_fetch_array(mysqli_query($conect, "select * from tb_produk where id_produk='$id'"));
//hapus gambar di folder
unlink("../assets/images/produk/$data[gambar_produk]");
//hapus data di tabel
$hapus=mysqli_query($conect, "DELETE from tb_produk where id_produk='$id'");
//jika hapus berhasil
if($hapus){
    echo"<script>alert('Data Berhasil di Hapus');document.location='produk.php'</script>";
}
else{ //jika gagal
    echo"<script>alert('Error Bos !!');document.location='produk.php'</script>";
}

}
?>

Hasil dari file hapus_produk.php akan menampilkan seperti ini

hapus-produk

Keenam, Buat file baru dengan nama cari_produk.php simpan di folder ADMINWEB

isi dari file cari_produk.php seperti ini

<?php
//pemanggilan file metatag
include "setting_metatag.php";

//pemanggilan file navbar
include "setting_navbar.php";
?>

        <div id="page-wrapper">

            <div class="container-fluid">
                <!-- .row -->
                <!-- Page Heading  breadcumb-->
                <div class="row">
                    <div class="col-lg-12">
                        <h3>
                            Data Produk
                            <a href="input_produk.php" title="Input data"><button name="input" class="btn btn-primary pull-right"><i class="fa fa-plus fa-fw"></i> Tambah Produk</button></a>

                        </h3>
                        <ol class="breadcrumb">
                            <li class="active">
                                <i class="fa fa-dashboard"></i> Home
                            </li>
                            <li class="active">
                                <i class="fa fa-list"></i> Data Produk
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->

                <!-- .row -->
                <div class="row">

                <!-- .col lg 12 -->
                    <div class="col-lg-12">

                    <!-- panel . (Pelajari cara membuat panel di bootstrap yah)-->
                        <div class="panel panel-default">

                        <!-- panel heading -->
                            <div class="panel-heading">
                            <div class="col-lg-6">
                            Daftar produk
                            </div>
                            <div class="col-lg-6">
                            <!-- form pencarian produk -->
                            <form action="cari_produk.php" method="get" class="form-inline text-right">
                            <input type="text" class="form-control" name="qw" placeholder="Cari Produk" required>
                            <button type="submit" class="btn btn-primary">Cari</button>
                            </form>
                            <!-- form pencarian produk -->
                            </div>
                            <div style="clear:both;"></div>
                            </div>
                        <!-- /.panel heading -->

                        <!-- panel body -->
                            <div class="panel-body">

                            <!-- /.tabel responsive -->
                                <div class="table-responsive">
                                    <table class="table table-bordered table-hover table-striped">
                                        <thead>
                                            <tr>
                                                <th>No</th>
                                                <th>Nama Produk</th>
                                                <th>Harga</th>
                                                <th>Gambar</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <?php
                                        $pg = isset( $_GET['pg'] ) ? $_GET['pg'] : "";
                                        $batas = 10; /*batas tampilan setiap halaman*/
                                        if ( empty( $pg ) ) {
                                        $posisi = 0;
                                        $pg = 1;
                                        } else {
                                        $posisi = ( $pg - 1 ) * $batas;
                                        }
                                        /*Jika variabel $pg kosong maka akan menampilkan halaman pertama dengan batas baris 10*/

                                        $ambildata=mysqli_query($conect, "select*from tb_produk, tb_kategori where tb_produk.id_kategori=tb_kategori.id_kategori and nama_produk LIKE '$_GET[qw]%' order by id_produk desc limit $posisi, $batas");
                                        $jumlah=mysqli_num_rows($ambildata);  /*mysql_num_rows untuk menghitung total baris di tabel databse*/
                                        if($jumlah == 0){  //jika tidak ada data
                                            ?>
                                        <tr>
                                            <td colspan="11">Tidak Terdapat Data</td>
                                        </tr>
                                        <?php
                                        }else{
                                        //jika ada data di tb_brand
                                        while($a=mysqli_fetch_array($ambildata)){ /*mysql_fetch array untuk mengambil data di setiap field di tabel databse*/
                                        ?>
                                        <tr>
                                            <td><?php echo $posisi=$posisi+1;?></td>
                                            <td><b><?php echo $a['nama_produk'];?></b>
                                            <br>Kategori : <?php echo $a['nama_kategori'];?>
                                            <br>Berat : <?php echo $a['berat_produk'];?> gr
                                            <br>Stok : <?php echo $a['stok_produk'];?>%
                                            <br>Diskon : <?php echo $a['diskon_produk'];?>%
                                            <br>Terjual : <?php echo $a['terjual'];?>
                                            </td>
                                            <td>Min. <?php echo $a['min_pembelian'];?> Harga /item : <?php echo number_format($a['harga_produk']);?>
                                            <?php
                                            if($a['min_order1'] != 0){
                                                ?>
                                            <br>Min. <?php echo $a['min_order1'];?> Harga / item : <?php echo number_format($a['harga_order1']);?>
                                            <?php
                                            }
                                            if($a['min_order2'] != 0){
                                                ?>
                                            <br>Min. <?php echo $a['min_order2'];?> Harga / item : <?php echo number_format($a['harga_order2']);?>
                                            <?php
                                            }
                                            if($a['min_order3'] != 0){
                                                ?>
                                            <br>Min. <?php echo $a['min_order3'];?> Harga / item : <?php echo number_format($a['harga_order3']);?>
                                            <?php
                                            }
                                            ?>
                                            </td>
                                            <td><img src="<?php echo $hostname;?>/assets/images/produk/<?php echo $a['gambar_produk'];?>" class="img-thumbnail" style="width:100px; height:100px;"></td>
                                            <td><a href="hapus_produk.php?id_produk=<?php echo $a['id_produk'];?>" onclick="return confirm('Yakin akan meghapus data ini')" title="Hapus data"><button class="btn btn-danger btn-sm"><i class="fa fa-trash-o fa-fw"></i> Hapus</button></a>
                                            <a href="edit_produk.php?id_produk=<?php echo $a['id_produk'];?>" title="Edit data"><button class="btn btn-primary btn-sm"><i class="fa fa-pencil-square-o fa-fw"></i> Edit</button> </a>
                                            </td>
                                        </tr>
                                        <?php
                                            }
                                        }
                                        ?>
                                        </tbody>
                                    </table>
                                </div>
                                <!-- /.tabel responsive -->

                                <div class="text-center">
                                    <?php
                                //script paging, untuk menampikan setiap halaman
                                $jml_data = mysqli_num_rows(mysqli_query($conect, "select*from tb_produk, tb_kategori where tb_produk.id_kategori=tb_kategori.id_kategori and nama_produk LIKE '$_GET[qw]%' order by id_produk desc"));
                                $JmlHalaman = ceil($jml_data/$batas); //ceil digunakan untuk pembulatan keatas
                                if($jml_data != 0){
                                if ( $pg > 1 ) {
                                $link = $pg-1;
                                $prev = "<a href='?pg=$link'><button name='prev' class='btn btn-primary btn-sm'>Prev</button></a> ";
                                } else {
                                $prev = "<button name='prev' class='btn btn-default btn-sm'>Prev </button> ";
                                }
                                $nmr = '';
                                for ( $i = 1; $i<= $JmlHalaman; $i++ ){

                                if ( $i == $pg ) {
                                $nmr .= "<button name='prev' class='btn btn-primary btn-sm'>$i</button> ";
                                } else {
                                $nmr .= "<a href='?pg=$i'><button name='prev' class='btn btn-default btn-sm'>$i</button></a> ";
                                }
                                }
                                if ( $pg < $JmlHalaman ) {
                                $link = $pg + 1;
                                $next = "<a href='?pg=$link'><button name='prev' class='btn btn-primary btn-sm'>Next</button></a> ";
                                } else {
                                $next = "<button name='prev' class='btn btn-default btn-sm'>Next</button> ";
                                }
                                echo $prev.$nmr.$next;
                                ?>
                                <br><br>
                                <span class="text-muted">Menampilkan <?php echo $jumlah; ?> dari <?php echo $jml_data; ?> Record </span>
                                <?php
                                }
                                ?>
                                </div>
                            </div>
                            <!-- /.panel body -->

                        </div>
                        <!-- /.panel -->

                    </div>
                    <!-- /.col lg 12-->

                </div>
                <!-- /.row -->


           </div>
            <!-- /.container-fluid -->

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

<?php
//pemanggilan file setting footer
include "setting_footer.php";

?>

Selesai

Develindo Web | Tutorial Pemrograman Website