Online Course

NK04 - Membuat Pengaturan Identitas Web dan Identitas Bisnis

Membuat pengaturan identitas website dan informasi bisnis

Sebelumnya anda telah membuat tabel tb_identitas pada database anda, nah sekarang anda akan menggunakan tabel tersebut.

Bagian 1 – Buat file baru dengan nama identitas.php simpan di folder ADMINWEB

Isi dari file identitas.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>
                            Identitas Website
                        </h3>
                        <ol class="breadcrumb">
                            <li class="active">
                                <i class="fa fa-dashboard"></i> Home
                            </li>
                            <li class="active">
                                <i class="fa fa-list"></i> Identitas website
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->
                
                <!-- .row -->
                <div class="row">

                <!-- .col lg 12 -->
                    <div class="col-lg-12">
                    <?php
                //ambil data berdasarkan id
                $tampildata=mysqli_query($conect, "select*from tb_identitas where id_identitas='1'");
                $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
                $deskripsi=mysqli_real_escape_string($conect, $_POST['deskripsi']);     //variabel dari name input deskripsi
                $key=mysqli_real_escape_string($conect, $_POST['key']);
                $footer=mysqli_real_escape_string($conect, $_POST['footer']);
                $pembuat=mysqli_real_escape_string($conect, $_POST['pembuat']);
                $hakcipta=mysqli_real_escape_string($conect, $_POST['hakcipta']);
                $slogan=mysqli_real_escape_string($conect, $_POST['slogan']);

                $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 Website anda </div>";
                }
                elseif(empty($slogan)){  //jika field slogan kosong
                $er_slogan="<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 Slogan Website anda </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> Deskripsikan Bisnis anda secara Singkat</div>";
                }
                elseif(strlen($deskripsi) > 160){ //jika field deskripsi > 160 karakter
                $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> Deskripsi Maksimal 160 Karakter</div>";
                }
                elseif(empty($key)){ //jika field key kosong
                $er_key="<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 Keyword Website anda</div>";
                }
                elseif(empty($pembuat)){ //jika field pembuat kosong
                $er_pembuat="<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 Pembuat Website anda</div>";
                }
                elseif(empty($hakcipta)){ //jika field hakcipta kosong
                $er_hakcipta="<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 Hak Cipta Bisnis anda</div>";
                }
                elseif(empty($footer)){ //jika field footer kosong
                $er_footer="<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 Footer Website anda</div>";
                }
                else{
                if(empty($foto)){  //jika foto tidak diubah maka
                $save=mysqli_query($conect, "UPDATE tb_identitas set nama_website='$nama', deskripsi='$deskripsi', katakunci='$key', hakcipta='$hakcipta', pembuat='$pembuat', footer='$footer' where id_identitas='1'");
                if($save){   //save
                echo " <script>alert('Data Berhasil Diubah');document.location='identitas.php'</script>";
                }
                else{    //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{ //jika semua field terpenuhi maka simpan gambar ke folder dan simpan data ke tabel

                unlink('../assets/images/logo/'.$lama); //hapus foto lama di folder
                move_uploaded_file($foto,"../assets/images/logo/$nama_foto");  //upload foto baru
                //simpan ke tabel database
                $save=mysqli_query($conect, "UPDATE tb_identitas set logo='$nama_foto', nama_website='$nama', deskripsi='$deskripsi', katakunci='$key', hakcipta='$hakcipta', pembuat='$pembuat', footer='$footer' where id_identitas='1'");
                if($save){   //save
                echo " <script>alert('Data Berhasil Diubah');document.location='identitas.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>";
                }
                }
                }

                }
                }
                ?>


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

                        <!-- panel heading -->
                            <div class="panel-heading">
                                Informasi Identitas Website anda
                            </div>
                        <!-- /.panel heading -->

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

                            <!-- col sm 4 -->
                            <div class="col-sm-7">
                            <!-- /.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">
                                <label>Nama Website</label>
                                <input type="text" class="form-control" placeholder="Nama Website" name="nama" value="<?php echo $b['nama_website'];?>" maxlength="50">
                            </div>
                            <?php echo $er_nama;?>
                            <div class="form-group">
                                <label>Slogan</label>
                                <input type="text" class="form-control" placeholder="Slogan / Moto" name="slogan" value="<?php echo $b['slogan'];?>" maxlength="100">
                            </div>
                            <?php echo $er_slogan;?>
                            <div class="form-group">
                            <label >Deskripsi</label>
                            <textarea name="deskripsi" class="form-control" rows="3" placeholder="Deskripsi Website"><?php echo $b['deskripsi'];?></textarea>
                            <span class="text-muted">Deskripsikan secara singkat max. 160 karakter</span>
                            </div>
                            <?php echo $er_deskripsi;?>
                            <div class="form-group">
                            <label>Key Words</label>
                            <textarea name="key" class="form-control" rows="2" placeholder="Key Word"><?php echo $b['katakunci'];?></textarea>
                            <small id="fileHelp" class="form-text text-muted">Gunakan koma setiap key word , Contoh : Toko Kaos, Distro Kaos, ...</small>
                            </div>
                            <?php echo $er_key;?>
                            <div class="form-group">
                                <label>Pembuat Web</label>
                                <input type="text" class="form-control" placeholder="Pembuat Website" name="pembuat" value="<?php echo $b['pembuat'];?>" maxlength="50">
                            </div>
                            <?php echo $er_pembuat;?>
                             <div class="form-group">
                                <label>Copt Right</label>
                                <input type="text" class="form-control" placeholder="Hak Cipta" name="hakcipta" value="<?php echo $b['hakcipta'];?>" maxlength="100">
                            </div>
                            <?php echo $er_hakcipta;?>
                            <div class="form-group">
                                <label>Footer</label>
                                <input type="text" class="form-control" placeholder="Footer" name="footer" value="<?php echo $b['footer'];?>" maxlength="100">
                            </div>
                            <?php echo $er_footer;?>
                            <div class="form-group">
                            <label>Logo Favicon</label>
                            <input type="file" name="foto" class="form-control-file" accept=".jpg, .png">
                            <small id="fileHelp" class="form-text text-muted">Logo akan muncul di Sebelah Judul website (lihat diatas tab browser anda)</small>
                            </div>
                            <?php echo $er_foto;?>
                            <input type="hidden" name="foto_lama" value="<?php echo $b['logo'];?>">
                            <button type="submit" name="simpan" class="btn btn-success">Simpan Perubahan</button>
                            </form>
                                <!-- /.form -->
                            </div>
                                <!-- /.col sm 7 -->
                                <div class="col-sm-3">
                            <img src="../assets/images/logo/<?php echo $b['logo'];?>" class="img-thumbnail" aria-describedby="helpBlock2" style="max-width:300px; max-height:300px;">
                            <span id="helpBlock2" class="help-block">Logo Favicon (Gunakan Ukuran Kecil)</span>
                            </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 identitas.php yang sudah anda buat akan menampilkan form seperti ini

identitas-web

Bagian 2 – Buat tabel baru dengan nama tb_infobis di database anda

tb_infobis memiliki struktur tabel seperti ini

tabel-infobis

Bagian 3 – Buat file baru dengan nama infobis.php simpan di folder ADMINWEB

Isi dari file infobis.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>
                            Informasi Bisnis
                        </h3>
                        <ol class="breadcrumb">
                            <li class="active">
                                <i class="fa fa-dashboard"></i> Home
                            </li>
                            <li class="active">
                                <i class="fa fa-list"></i> Informasi Bisnis
                            </li>
                        </ol>
                    </div>
                </div>
                <!-- /.row -->
                
                <!-- .row -->
                <div class="row">

                <!-- .col lg 12 -->
                    <div class="col-lg-12">
                    <?php
                //ambil data berdasarkan id
                $tampildata=mysqli_query($conect, "select*from tb_infobis where id_infobis='1'");
                $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
                $deskripsi=mysqli_real_escape_string($conect, $_POST['deskripsi']);     //variabel dari name input deskripsi
                $alamat=mysqli_real_escape_string($conect, $_POST['alamat']);
                $telp=mysqli_real_escape_string($conect, $_POST['telp']);
                $web=mysqli_real_escape_string($conect, $_POST['web']);
                $email=mysqli_real_escape_string($conect, $_POST['email']);

                $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 Bisnis anda </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> Deskripsikan Bisnis anda secara lengkap</div>";
                }
                elseif(empty($alamat)){ //jika field alamat kosong
                $er_alamat="<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 Alamat Bisnis anda</div>";
                }
                elseif(empty($telp)){ //jika field telp kosong
                $er_telp="<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 Nomor Telp Bisnis anda</div>";
                }
                elseif(empty($email)){ //jika field email kosong
                $er_email="<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 Email Bisnis anda</div>";
                }
                elseif(empty($web)){ //jika field web kosong
                $er_web="<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 Web Bisnis anda</div>";
                }
                else{
                if(empty($foto)){  //jika foto tidak diubah maka
                $save=mysqli_query($conect, "UPDATE tb_infobis set nama_bisnis='$nama', deskripsi_bisnis='$deskripsi', alamat_bisnis='$alamat', telp_bisnis='$telp', email_bisnis='$email', web_bisnis='$web' where id_infobis='1'");
                if($save){   //save
                echo " <script>alert('Data Berhasil Diubah');document.location='infobis.php'</script>";
                }
                else{    //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{ //jika semua field terpenuhi maka simpan gambar ke folder dan simpan data ke tabel

                unlink('../assets/images/logo/'.$lama); //hapus foto lama di folder
                move_uploaded_file($foto,"../assets/images/logo/$nama_foto");  //upload foto baru
                //simpan ke tabel database
                $save=mysqli_query($conect, "UPDATE tb_infobis set logo_bisnis='$nama_foto', nama_bisnis='$nama', deskripsi_bisnis='$deskripsi', alamat_bisnis='$alamat', telp_bisnis='$telp', email_bisnis='$email', web_bisnis='$web' where id_infobis='1'");
                if($save){   //save
                echo " <script>alert('Data Berhasil Diubah');document.location='infobis.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>";
                }
                }
                }

                }
                }
                ?>

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

                        <!-- panel heading -->
                            <div class="panel-heading">
                                Informasi Bisnis Anda
                            </div>
                        <!-- /.panel heading -->

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

                            <!-- col sm 4 -->
                            <div class="col-sm-7">
                            <!-- /.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">
                                <label>Nama Bisnis</label>
                                <input type="text" class="form-control" placeholder="Nama Bisnis Anda" name="nama" value="<?php echo $b['nama_bisnis'];?>" maxlength="50">
                            </div>
                            <?php echo $er_nama;?>
                            <div class="form-group">
                            <label for="exampleTextarea">Deskripsi Bisnis</label>
                            <textarea name="deskripsi" class="form-control" id="exampleTextarea" rows="4" placeholder="Deskripsi Bisnis Anda"><?php echo $b['deskripsi_bisnis'];?></textarea>
                            </div>
                            <?php echo $er_deskripsi;?>
                            <div class="form-group">
                            <label for="exampleTextarea">Alamat </label>
                            <textarea name="alamat" class="form-control" id="exampleTextarea" rows="3" placeholder="Alamat Perusahaan"><?php echo $b['alamat_bisnis'];?></textarea>
                            </div>
                            <?php echo $er_alamat;?>
                            <div class="form-group">
                                <label>No Telp / Hp</label>
                                <input type="text" class="form-control" placeholder="No Telp / Hp" name="telp" value="<?php echo $b['telp_bisnis'];?>" maxlength="50">
                            </div>
                            <?php echo $er_telp;?>
                             <div class="form-group">
                                <label>Email</label>
                                <input type="text" class="form-control" placeholder="Email " name="email" value="<?php echo $b['email_bisnis'];?>" maxlength="100">
                            </div>
                            <?php echo $er_email;?>
                            <div class="form-group">
                                <label>Website</label>
                                <input type="text" class="form-control" placeholder="Website bisnis anda" name="web" value="<?php echo $b['web_bisnis'];?>" maxlength="100">
                            </div>
                            <?php echo $er_web;?>
                            <div class="form-group">
                            <label>Logo </label>
                            <input type="file" name="foto" class="form-control-file" accept=".jpg, .png">
                            <small id="fileHelp" class="form-text text-muted">Logo Perusahaan akan muncul di header website</small>
                            </div>
                            <?php echo $er_foto;?>
                            <input type="hidden" name="foto_lama" value="<?php echo $b['logo_bisnis'];?>">
                            <button type="submit" name="simpan" class="btn btn-success">Simpan Perubahan</button>
                            </form>
                                <!-- /.form -->
                            </div>
                                <!-- /.col sm 7 -->
                                <div class="col-sm-3">
                            <img src="../assets/images/logo/<?php echo $b['logo_bisnis'];?>" class="img-thumbnail" aria-describedby="helpBlock2" style="max-width:300px; max-height:300px;">
                            <span id="helpBlock2" class="help-block">Logo Bisnis</span>
                            </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 infobis.php akan menampilkan form seperti ini

informassi-bisnis

Oke, selesai

Develindo Web | Tutorial Pemrograman Website