-->

[TUTORIAL] - Cara Membuat Aplikasi Data Pegawai Dengan Menggunakan PHP & MYSQL






MEMBUAT
APLIKASI DATA PEGAWAI DENGAN MENGGUNAKAN PHP & MYSQL





Langkah Pertama :





Sebelum anda
mengerjakan Aplikasi tersebut buat lah folder di mana Localhost server anda
yang anda install. Cth :





C:\Apache\htdocs





                                |-
pegawai1





                                                |-
images





Langkah Kedua : MEMBUAT DATABASE MYSQL





Buatlah database MySQL dengan nama pegawai .
dengan structure dibawah ini :





DROP TABLE IF EXISTS `pegawai`;





CREATE TABLE IF NOT EXISTS `pegawai` (





  `nip`
varchar(10) NOT NULL DEFAULT '' ,





  `nama`
varchar(30) NOT NULL DEFAULT '' ,





 
`tgllahir` date NOT NULL DEFAULT '0000-00-00' ,





 
`jenkel` enum('0','1') NOT NULL DEFAULT '0' ,





 
`alamat` text NOT NULL DEFAULT '' ,





 
`namafoto` varchar(50) NOT NULL DEFAULT '' ,





 
PRIMARY KEY (`nip`),





  UNIQUE
KEY nim (`nip`),





   KEY
nim_2 (`nip`)





);





Langkah Ketiga : MEMBUAT FILE CASCADING
STYLE SHEET (CSS)





Untuk memperindah tampilan lay out Content, Buatlah
program di bawah ini, kemudian simpan dengan Nama file : style.css ke dalam folder
pegawai1





Quote :





/* CSS Document */





/* andiofi */





body {





                background-color:#ffffff;





                font-family:"Trebuchet
MS", sans-serif;





                }





a {





                text-decoration:
none;





                color:#0000ff;





                }





a:hover {





                color:#ff0000;





}





#main_container {





                width:750px;





                border:
#000000 1px solid;





                margin:
0 auto;





                background-color:#FEFEFE;





                }





#header {





                height:174px;





                width:100%;





                background-image:
url(images/clock.jpg);





                background-repeat:
no-repeat;





                }





h1 {





                size:30px;





                float:right;





                vertical-align:middle;





                margin:
10px 20px 0 0;





                font-family:
Impact, Arial, Helvetica, sans-serif;





                }





h2 {





                padding-left:
5px;





                margin:
5px 0px 0px 0px;





                }





p, table {





                size:
10px;





                margin:0px;





                padding:10px;





                text-align:justify;





                }





#navigation {





                width:100%;





                border-top:  #000000 1px solid;





                border-bottom:
#000000 1px solid;





                text-align:center;





                }





#navigation a {





                padding:3px;





                }





#content {





                width:100%;





                }





#footer {





                width:100%;





                border-top:  #000000 1px solid;





                text-align:center;





                font-size:9px;





                }





#tabel {





                background-color:#ffffff;  





                padding:2px;





                border:1px
solid #222222;





                margin:2px;





}              





#tabel th {





                color:#ffffff;





                background-color:#222222;





                padding:2px;       





}





Langkah Keempat : MEMBUAT FILE KONEKSI
DATABASE MYSQL





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : koneksi.inc.php ke dalam folder pegawai1





Quote :





<?php





//file koneksi untuk menghubungkan dengan
database             





$host = "localhost";             //hostname MySQL





$user = "root";                     //user mysql





$pass = "";                             //password mysql





$dbnm = "pegawai";            //nama database





//koneksi database





$conn = mysql_connect ($host, $user, $pass);





if ($conn) {





                $buka
= mysql_select_db ($dbnm);





                if
(!$buka) {





                                die
("Database tidak dapat dibuka");              





                }





} else {





                die
("Server MySQL tidak terhubung");          





}





?>





Langkah Keempat : MEMBUAT TAMPILAN
MENU UTAMA





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : utama.php ke dalam folder pegawai1





Quote :





<div id="content">





                <h2>Selamat
Datang di Sistem Informasi Kepegawaian PT. XYZ</h2>





                <p>Sistem
Informasi Kepegawaian ini dibuat untuk memenuhi contoh matakuliah Pemrograman
Web Design di





                <a
href="http://www.amikstiekomsu.ac.id" target=_blank>AMIK-STIEKOM
SUMATERA UTARA</a>, Dosen : Supiyandi.</p>





                <p>Dalam
Sistem Kepegawaian ini, Anda dapat <a
href="index.php?page=input">menginput</a> data pegawai,





                <a
href="index.php?page=tampil">melihat</a> data pegawai, dan
mengedit serta delete data pegawai</p>





                <p>Njoyed..With
This Page..</p>





</div>





Langkah Kelima : MEMBUAT TAMPILAN AWAL
DATA PEGAWAI





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : index.php ke dalam folder pegawai1





Quote :





<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





<html
xmlns="http://www.w3.org/1999/xhtml">





<head>





<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />





<title>Sistem Kepegawaian</title>





<link href="style.css"
rel="stylesheet" type="text/css" />





</head>





<body>





<div id="main_container">





<div id="header">





<h1>Sistem Informasi Kepegawaian PT.
XYZ</h1>





</div>





<div id="navigation">





                <a
href="index.php">Home</a>





                <a
href="index.php?page=input">Input Data Pegawai</a>





                <a
href="index.php?page=tampil">Tampil Data Pegawai</a>





                <a
href="index.php?page=about">Tentang Saya</a>





</div>





<?php





$page = (isset($_GET['page']))? $_GET['page']
: "main";





switch ($page) {





                case
'input' : include "input_peg.php"; break;





                case
'edit' : include "edit_peg.php"; break;





                case
'delete' : include "delete_peg.php"; break;





                case
'tampil' : include "tampil.php"; break;





                case
'foto' : include "foto.php"; break;





                case
'about' : include "about.php"; break;





                case
'main' :





                default
: include 'utama.php';          





}





?>





<div id="footer">&copy;
2012 <a href="mailto:andie.itech@gmail.com">Andie.Ofie</a>
| Design By <a href="http://nzsrasaoke.wordpress.com">Andie.ofie</a>
</div>





</div>





</body>





</html>





Langkah Keenam : MEMBUAT TAMPILAN
INPUT PEGAWAI





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : input_peg.php ke dalam folder pegawai1





Quote :





<?php





include "koneksi.php"; //mengambil
dan menghubungkan file koneksi ke mysql





//proses input berita





if (isset($_POST['Input'])) {





                $nip
= addslashes (strip_tags ($_POST['nip']));





                $nama
= addslashes (strip_tags ($_POST['nama']));





                $tgllahir
= $_POST['thn']."-".$_POST['bln']."-".$_POST['tgl'];





                $jenkel
= $_POST['jenkel'];





                $alamat
= addslashes (strip_tags ($_POST['alamat']));





                $namafoto
= $_FILES['foto']['name'];





                if
(strlen ($nip) != 10) {





                                die
("NIP harus 10 digit"); 





                }





                if
(strlen($namafoto)>0) {





                                //upload





                                if
(is_uploaded_file($_FILES['foto']['tmp_name'])) {





                                                move_uploaded_file
($_FILES['foto']['tmp_name'], "images/".$namafoto);





                                }





                }





                //insert
ke tabel





                $query
= "INSERT INTO pegawai
VALUES('$nip','$nama','$tgllahir','$jenkel','$alamat','$namafoto')";





                $sql
= mysql_query ($query) or die (mysql_error());





                if
($sql) {





                                echo
"<h2><font color=blue>Data Pegawai telah berhasil
ditambahkan</font></h2>";    





                }
else {





                                echo
"<h2><font color=red>Data Pegawai gagal
ditambahkan</font></h2>";     





                }





}





?>





<div id="content">





                <h2>Input
Data Pegawai</h2>





                <FORM
ACTION="" METHOD="POST" NAME="input"
enctype="multipart/form-data">





                                <table
cellpadding="0" cellspacing="0" border="0"
width="700">





                                                <tr>





                                                                <td
width="200">NIP</td>





                                                                <td>:
<input type="text" name="nip" size="15"
maxlength="10"></td>





                                                </tr>





                                                <tr>





                                                                <td>Nama</td>





                                                                <td>:
<input type="text" name="nama" size="30"
maxlength="30"></td>





                                                </tr>





                                                <tr>





                                                                <td>Tanggal
Lahir</td>





                                                                <td>:





                                                                <select
name="tgl">





                                                                <?





                                                                                for
($i=1; $i<=31; $i++) {





                                                                                                $tg
= ($i<10) ? "0$i" : $i;





                                                                                                echo
"<option value='$tg'>$tg</option>";    





                                                                                }





                                                                ?>





                                                                </select>
-





                                                                <select
name="bln">





                                                                <?





                                                                                for
($i=1; $i<=12; $i++) {





                                                                                                $bl
= ($i<10) ? "0$i" : $i;





                                                                                                echo
"<option value='$bl'>$bl</option>";    





                                                                                }





                                                                ?>





                                                                </select>
-





                                                                <select
name="thn">





                                                                <?





                                                                                for
($i=1970; $i<=2000; $i++) {





                                                                                                echo
"<option value='$i'>$i</option>";        





                                                                                }





                                                                ?>





                                                                </select>





                                                                </td>





                                                </tr>





                                                <tr>





                                                                <td>Jenis
Kelamin</td>





                                                                <td>:
<input type="radio" name="jenkel" value="0"
checked> Pria &nbsp;&nbsp;





                                                                <input
type="radio" name="jenkel" value="1"> Wanita</td>





                                                </tr>





                                                <tr>





                                                                <td>Alamat</td>





                                                                <td>:
<textarea name="alamat" cols="40"
rows="5"></textarea></td>





                                                </tr>





                                                <tr>





                                                                <td>Foto</td>





                                                                <td>:
<input type="file" name="foto"/></td>





                                                </tr>





                                                <tr>





                                                <td>&nbsp;</td>





                                                <td>&nbsp;&nbsp;<input
type="submit" name="Input" value="Input
Data">&nbsp;





                                                 <input type="reset"
name="reset" value="Reset"></td>





                                                </tr>





                                </table>





                </FORM>





</div>





Langkah Keenam : MEMBUAT TAMPILAN
MENAMPILKAN DATA PEGAWAI





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : tampil.php ke dalam folder pegawai1





Quote :





<?php





include "koneksi.php"; //mengambil
dan menghubungkan file koneksi ke mysql





?>





<div id="content">





                <h2>Data
Pegawai</h2>





                <table  id="tabel">





                <tr>





                                <th
width="5%">No</td>





                                <th
width="10%">NIP</td>





                                <th
width="20%">Nama</td>





                                <th
width="15%">Tgl Lahir</td>





                                <th
width="20%">Jenis Kelamin</td>





                                <th
width="30%">Alamat</td>





                                <th>Action</td>





                </tr>





                <?





                $no
= 1;





                $query
= "SELECT nip, nama, tgllahir, jenkel, alamat





                                                  FROM pegawai ORDER BY nip";





                $sql
= mysql_query ($query);





                while
($hasil = mysql_fetch_array ($sql)) {





                                $nip
= $hasil['nip'];





                                $nama
= stripslashes ($hasil['nama']);





                                $jenkel
= ($hasil['jenkel']==0)?"Laki-laki" : "Wanita";





                                $tgllhr
= stripslashes ($hasil['tgllahir']);





                                $alamat
= stripslashes ($hasil['alamat']);





                                $warna
= ($no%2==1)?"#ffffff":"#efefef";





                                //





                                //tampilkan
data pegawai





                ?>





                                <tr
bgcolor="<?=$warna?>">





                                                <td><?=$no?></td>





                                                <td><?=$nip?></td>





                                                <td><?=$nama?></td>





                                                <td><?=$tgllhr?></td>





                                                <td><?=$jenkel?></td>





                                                <td><?=$alamat?></td>





                                                <td>





                                                <a
href="index.php?page=foto&nip=<?=$nip?>">Foto</a><br/>





                                                <a
href="index.php?page=edit&nip=<?=$nip?>">Edit</a><br/>





                                                <a
href="index.php?page=delete&nip=<?=$nip?>">Delete</a></td>





                                </tr>      





                <?
$no++; }?>





                </table>





</div>





Langkah Ketujuh : MEMBUAT TAMPILAN
EDIT DATA PEGAWAI





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : edit_peg.php ke dalam folder pegawai1





Quote :





<?php





include "koneksi.php"; //mengambil
dan menghubungkan file koneksi ke mysql





if (isset($_GET['nip'])) {





                $nip
= $_GET['nip'];





} else {





                die
("Error. No Nip Selected! ");      





}





$query = "SELECT nip, nama, tgllahir,
jenkel, alamat, namafoto FROM pegawai WHERE nip='$nip'";





$sql = mysql_query ($query);





$hasil = mysql_fetch_array ($sql);





$nip = $hasil['nip'];





$nama = stripslashes ($hasil['nama']);





$jenkel = $hasil['jenkel'];





list($thn,$bln,$tgl) = explode
("-",$hasil['tgllahir']);





$alamat = stripslashes ($hasil['alamat']);





$namafoto = stripslashes ($hasil['namafoto']);





//proses edit berita





if (isset($_POST['Edit'])) {





                $nip
= $_POST['hnip'];





                $nama
= addslashes (strip_tags ($_POST['nama']));





                $tgllahir
= $_POST['thn']."-".$_POST['bln']."-".$_POST['tgl'];





                $jenkel
= $_POST['jenkel'];





                $alamat
= addslashes (strip_tags ($_POST['alamat']));





                $namafoto
= $_FILES['foto']['name'];





                if
(strlen($namafoto)>0) {





                                //upload





                                if
(is_uploaded_file($_FILES['foto']['tmp_name'])) {





                                                move_uploaded_file
($_FILES['foto']['tmp_name'], "images/".$namafoto);





                                                mysql_query
("UPDATE pegawai SET namafoto='$namafoto' WHERE nip='$nip'");





                                }





                }





                //update
data





                $query
= "UPDATE pegawai SET nama='$nama',tgllahir='$tgllahir',jenkel='$jenkel',





                                                  alamat='$alamat' WHERE nip='$nip'";





                $sql
= mysql_query ($query);





                if
($sql) {





                                echo
"<h2><font color=blue>Data Pegawai telah berhasil
diedit</font></h2>"; 





                }
else {





                                echo
"<h2><font color=red>Data Pegawai gagal
diedit</font></h2>";  





                }





}





?>





<div id="content">





                <h2>Edit
Data Pegawai</h2>





                <FORM
ACTION="" METHOD="POST" NAME="input"
enctype="multipart/form-data">





                                <table
cellpadding="0" cellspacing="0" border="0"
width="700">





                                                <tr>





                                                                <td
width="200">NIP</td>





                                                                <td>:
<b><?=$nip?></b></td>





                                                </tr>





                                                <tr>





                                                                <td>Nama</td>





                                                                <td>:
<input type="text" name="nama" size="30"
maxlength="30" value="<?=$nama?>"></td>





                                                </tr>





                                                <tr>





                                                                <td>Tanggal
Lahir</td>





                                                                <td>:





                                                                <select
name="tgl">





                                                                <?





                                                                                for
($i=1; $i<=31; $i++) {





                                                                                                $tg
= ($i<10) ? "0$i" : $i;





                                                                                                $sele
= ($tg==$tgl)? "selected" : "";





                                                                                                echo
"<option value='$tg' $sele>$tg</option>";         





                                                                                }





                                                                ?>





                                                                </select>
-





                                                                <select
name="bln">





                                                                <?





                                                                                for
($i=1; $i<=12; $i++) {





                                                                                                $bl
= ($i<10) ? "0$i" : $i;





                                                                                                $sele
= ($bl==$bln)?"selected" : "";





                                                                                                echo
"<option value='$bl' $sele>$bl</option>";         





                                                                                }





                                                                ?>





                                                                </select>
-





                                                                <select
name="thn">





                                                                <?





                                                                                for
($i=1970; $i<=2000; $i++) {





                                                                                                $sele
= ($i==$thn)?"selected" : "";





                                                                                                echo
"<option value='$i' $sele>$i</option>";              





                                                                                }





                                                                ?>





                                                                </select>





                                                                </td>





                                                </tr>





                                                <tr>





                                                                <td>Jenis
Kelamin</td>





                                                                <td>:
<input type="radio" name="jenkel" value="0"
<? echo ($jenkel==0)?"checked":""; ?>> Pria
&nbsp;&nbsp;





                                                                <input
type="radio" name="jenkel" value="1" <? echo
($jenkel==1)?"checked":""; ?>> Wanita</td>





                                                </tr>





                                                <tr>





                                                                <td>Alamat</td>





                                                                <td>:
<textarea name="alamat" cols="40"
rows="5"><?=$alamat?></textarea></td>





                                                </tr>





                                                <tr>





                                                                <td>Foto</td>





                                                                <td>:
<input type="file" name="foto"/> Foto:
<?=$namafoto?></td>





                                                </tr>





                                                <tr>





                                                                <td>&nbsp;</td>





                                                                <td>&nbsp;&nbsp;





                                                                <input
type="hidden" name="hnip"
value="<?=$nip?>">





                                                                <input
type="submit" name="Edit" value="Edit
Data">&nbsp;





                                                                <input
type="reset" name="reset"
value="Reset"></td>





                                                </tr>





                                </table>





                </FORM>





</div>





Langkah Kedelapan : MEMBUAT TAMPILAN
HAPUS DATA PEGAWAI





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : delete_peg.php ke dalam folder pegawai1





Quote :





<?php





include "koneksi.php"; //mengambil
dan menghubungkan file koneksi ke mysql





if (isset($_GET['nip'])) {





                $nip
= $_GET['nip'];





} else {





                die
("Error. No nip Selected! ");       





}





?>





<div id="content">





                <?





                //proses
delete berita





                if
(!empty($nip) && $nip != "") {





                                $query
= "DELETE FROM pegawai WHERE nip='$nip'";





                                $sql
= mysql_query ($query);





                                if
($sql) {





                                                echo
"<h2><font color=blue>Data Pegawai telah berhasil
dihapus</font></h2>";             





                                }
else {





                                                echo
"<h2><font color=red>Data pegawai gagal
dihapus</font></h2>";              





                                }





                                echo
"Klik <a href='index.php?page=tampil'>di sini</a> untuk
kembali ke halaman data pegawai";





                }
else {





                                die
("Access Denied");       





                }





                ?>





</div>





Langkah Kesembilan : MEMBUAT TAMPILAN MENAMPILKAN
PHOTO PEGAWAI





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : foto.php ke dalam folder pegawai1





Qoute :





<?php





include "koneksi.php"; //mengambil
dan menghubungkan file koneksi ke mysql





?>





<div id="content">





                <h2>Foto
Pegawai</h2>





                <div
align="center">





                <?





                $nip
= (isset($_GET['nip']))? $_GET['nip'] : 0;





                if
($nip ==0) die ("no id selected");





                $query
= "SELECT namafoto FROM pegawai WHERE nip='$nip'";





                $sql
= mysql_query ($query);





                $hasil
= mysql_fetch_array ($sql);





                $foto
= $hasil['namafoto'];





                if
(empty($foto)) echo "<strong>Foto pegawai tidak
tersedia</strong>";





                echo
"<img src='images/$foto' />";





                ?>





                </div>





</div>





Langkah Kesepuluh : MEMBUAT TAMPILAN
BIODATA PERSONAL ATAU KELOMPOK





Buatlah program di bawah ini, kemudian simpan
dengan Nama file : about.php ke dalam folder pegawai1





Quote :





<div id="content">





                <h2>Yang
Membuat Program ... </h2>





                <p>





                NPM
: <b>Ketik NPM kamu ... </b><br/>





                Nama
: <b>Ketik Nama Kamu ...</b><br/>





                Matakuliah
: <b>Pemrograman Web Design, Dosen Pengasuh : Supiyandi
...</b><br/>





                Kelompok
: <b>Ketik Kelompok Kamu ...</b><br/>





                </p>





</div>


LihatTutupKomentar