Untuk membuat sebuah program tentunya kita memerlukan sebuah perancangan database, dibawah ini adalah rencana pembuatan tabelnya.
Nama Database booklet
CREATE DATABASE booklet ;
Nama Tabel biografi
CREATE TABLE biografi (
id INT( 4 ) NOT NULL AUTO_INCREMENT ,
nis INT( 10 ) NOT NULL ,
nm VARCHAR( 25 ) NOT NULL ,
jk VARCHAR( 1 ) NOT NULL ,
tmp_lhr VARCHAR( 35 ) NOT NULL ,
tgl_lhr DATE NOT NULL ,
kls VARCHAR( 6 ) NOT NULL ,
kpk VARCHAR( 30 ) NOT NULL ,
almt TEXT NOT NULL ,
hp INT( 12 ) NOT NULL ,
fb VARCHAR( 35 ) NOT NULL ,
email VARCHAR( 35 ) NOT NULL ,
PRIMARY KEY ( `nis` ) ,
UNIQUE (
nis INT( 10 ) NOT NULL ,
nm VARCHAR( 25 ) NOT NULL ,
jk VARCHAR( 1 ) NOT NULL ,
tmp_lhr VARCHAR( 35 ) NOT NULL ,
tgl_lhr DATE NOT NULL ,
kls VARCHAR( 6 ) NOT NULL ,
kpk VARCHAR( 30 ) NOT NULL ,
almt TEXT NOT NULL ,
hp INT( 12 ) NOT NULL ,
fb VARCHAR( 35 ) NOT NULL ,
email VARCHAR( 35 ) NOT NULL ,
PRIMARY KEY ( `nis` ) ,
UNIQUE (
`id`
)Database sudah berhasil dibuat, selanjutnya kita siapkan halaman input data, perlu diketahui bahwa saya beserta anak didik saya menggunakan program Adobe Dreamweaver CS3 sebagai program untuk membuat Front End/Halaman depan program. Berikut Scripnya dan dilanjutkan dengan tampilannya.
Scriptnya dibawah ini :
<form action="proses.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="100%" border="0">
<tr>
<th height="40" colspan="4" scope="col"><span class="style2">INPUT DATA BIOGRAFI</span></th>
</tr>
<tr>
<td width="29%"> </td>
<td width="16%">NIS</td>
<td width="3%"><div align="center">:</div></td>
<td width="52%"><input name="nis" type="text" id="nis" size="20" maxlength="10" /></td>
</tr>
<tr>
<td> </td>
<td>NAMA</td>
<td><div align="center">:</div></td>
<td><input name="nama" type="text" id="nama" size="45" maxlength="25" /></td>
</tr>
<tr>
<td> </td>
<td>JENIS KELAMIN</td>
<td><div align="center">:</div></td>
<td><p>
<select name="jk" id="jk">
<option value="L">L</option>
<option value="P">P</option>
</select>
</p> </td>
</tr>
<tr>
<td> </td>
<td>TEMPAT LAHIR</td>
<td><div align="center">:</div></td>
<td><input name="tmplhr" type="text" id="tmplhr" size="45" maxlength="35" /></td>
</tr>
<tr>
<td> </td>
<td>TANGGAL LAHIR</td>
<td><div align="center">:</div></td>
<td>Tgl
<select name="tgl" id="tgl">
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
Bln
<select name="bln" id="bln">
<option value="JANUARI">JANUARI</option>
<option value="FEBRUARI">FEBRUARI</option>
<option value="MARET">MARET</option>
<option value="APRIL">APRIL</option>
<option value="MEI">MEI</option>
<option value="JUNI">JUNI</option>
<option value="JULI">JULI</option>
<option value="AGUSTUS">AGUSTUS</option>
<option value="SEPTEMBER">SEPTEMBER</option>
<option value="OKTOBER">OKTOBER</option>
<option value="NOVEMBER">NOVEMBER</option>
<option value="DESEMBER">DESEMBER</option>
</select>
Thn
<select name="thn" id="thn">
<option value="1990">1990</option>
<option value="1991">1991</option>
<option value="1992">1992</option>
<option value="1993">1993</option>
<option value="1994">1994</option>
<option value="1995">1995</option>
<option value="1996">1996</option>
<option value="1997">1997</option>
<option value="1998">1998</option>
<option value="1999">1999</option>
<option value="2000">2000</option>
</select></td>
</tr>
<tr>
<td> </td>
<td>KELAS</td>
<td><div align="center">:</div></td>
<td><select name="kls" id="kls">
<option value="XII TKB">XII TKB</option>
<option value="XII TGB">XII TGB</option>
<option value="XII TFN">XII TFN</option>
<option value="XII TPM">XII TPM</option>
<option value="XII TKR">XII TKR</option>
<option value="XII TKJ">XII TKJ</option>
</select></td>
</tr>
<tr>
<td> </td>
<td>KOMPETENSI KEAHLIAN</td>
<td><div align="center">:</div></td>
<td><select name="kpk" id="kpk">
<option value="TEKNIK KONSTRUKSI BATU BETON">TEKNIK KONSTRUKSI BATU BETON</option>
<option value="TEKNIK GAMBAR BANGUNAN">TEKNIK GAMBAR BANGUNAN</option>
<option value="TEKNIK FURNITURE">TEKNIK FURNITURE</option>
<option value="TEKNIK PEMESINAN">TEKNIK PEMESINAN</option>
<option value="TEKNIK KENDARAAN RINGAN">TEKNIK KENDARAAN RINGAN</option>
<option value="TEKNIK KOMPUTER JARINGAN">TEKNIK KOMPUTER JARINGAN</option>
</select></td>
</tr>
<tr>
<td> </td>
<td>ALAMAT</td>
<td><div align="center">:</div></td>
<td><textarea name="almt" cols="35" rows="5" id="almt"></textarea></td>
</tr>
<tr>
<td> </td>
<td>NO HP</td>
<td><div align="center">:</div></td>
<td><input name="hp" type="text" id="hp" size="45" maxlength="12" /></td>
</tr>
<tr>
<td> </td>
<td>AKUN FACEBOOK</td>
<td><div align="center">:</div></td>
<td><input name="fb" type="text" id="fb" size="45" maxlength="30" /></td>
</tr>
<tr>
<td> </td>
<td>AKUN EMAIL</td>
<td><div align="center">:</div></td>
<td><input name="email" type="text" id="email" size="45" maxlength="30" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><input type="submit" name="kirim" id="kirim" value="KIRIM" />
<input type="reset" name="batal" id="batal" value="BATAL" /></td>
</tr>
</table>
</form>
Setelah Database terbuat dan Halaman input data sudah siap, maka selanjutnya kita akan memasukan data dan menghubungkannya dengan menggunakan bahasa pemograman PHP. Ada 3 file PHP yang akan kita buat sebagai berikut :
1. file konektor
2. file proses
3. file tampilan data
Baik kita akan mulai dengan membuat file konektor. (lihat scripting dibawah)
1. Script file konektor dibawah ini (konektor.php)
<?php
$db_hostname="localhost";
$db_username="root";
$db_password="";
$db_name="booklet";
function connect_db() {
global $db_hostname, $db_username, $db_password, $db_name;
$conn = mysql_connect($db_hostname, $db_username, $db_password) or die ("Sorry cannot connect to the database because: " . mysql_error());;
mysql_select_db($db_name);
}
?>
$db_hostname="localhost";
$db_username="root";
$db_password="";
$db_name="booklet";
function connect_db() {
global $db_hostname, $db_username, $db_password, $db_name;
$conn = mysql_connect($db_hostname, $db_username, $db_password) or die ("Sorry cannot connect to the database because: " . mysql_error());;
mysql_select_db($db_name);
}
?>
<?php
require_once("konektor.php"); //memanggil file konektor.php
connect_db(); // memanggil fungsi connect_db yang ada di file database.php
if($_POST["tombol"]=="Kirim")
{
$nis =$_POST["nis"];
$nama =$_POST["nama"];
$jk =$_POST["jk"];
$tmp_lhr =$_POST["tmp_lhr"];
$tgl_lhr =date["d-m-y"];
$kls =$_POST["kls"];
$kpk =$_POST["kpk"];
$almt =$_POST["almt"];
$hp =$_POST["hp"]; $fb =$_POST["fb"];
$email =$_POST["email"];
$query="INSERT INTO biografi(nis,nama,jk,tmp_lhr,tgl_lhr,kls,kpk,almt,hp,fb,email) VALUES('$nis', '$nama', '$jk', '$tmp_lhr', '$tgl_lhr', '$kls', '$kpk', '$almt', '$hp', '$fb', '$email')";
$result=mysql_query($query);
if($result){
echo "data berhasil disimpan";
}else{
echo "data gagal disimpan";
}
}
?>
3. Script file tampilan data (tampil.php)
<html>
<head><title>Daftar Guestbook</title></head>
<body>
<?php
require_once("koneksi.php");
connect_db();
$query=mysql_query("SELECT * FROM biografi");
$row=mysql_fetch_row($query);
if(!$row)
echo "tabel biografi kosong";
else
{
echo "<h2>BIOGRAFI SISWA TINGKAT XII</h2>";
echo "<table border=1>";
echo "<tr>";
echo "<td>No</td>";
echo "<td>NIS</td>";
echo "<td>Nama</td>";
echo "<td>Jenis Kelamin</td>";
echo "<td>Tempat, Tanggal Lahir</td>";
echo "<td>Kelas</td>";
echo "<td>Kompetensi Keahlian</td>";
echo "<td>Alamat</td>";
echo "<td>HP</td>";
echo "<td>Facebook</td>";
echo "<td>Email</td>";
echo "</tr>";
do{
list($id,$nama,$email,$alamat,$kota)=$row;
echo "<tr>";
echo "<td>$id</td>";
echo "<td>$nis </td>";
echo "<td>$nm </td>";
echo "<td>$jk </td>";
echo "<td>$tmp_lhr, $tgl_lhr </td>";
echo "<td>$kls </td>";
echo "<td>$kpk </td>";
echo "<td>$almt </td>";
echo "<td>$hp </td>";
echo "<td>$fb </td>";
echo "<td>$email </td>";
echo "</tr>";
}while($row=mysql_fetch_row($query));
}
?>
</body>
</html>
makasih gan, sangat membantu
ReplyDelete