PHP berbasis Object Oriented Programming (OOP
1. Tampilan Menu home utama php.
2. Tampilan menu input data diri php.
3. Tampilan menu tabel data diri php.
4. Tampilan menu about php.
Dibawah ini merupakan source code untuk melakukan perintah pembuatan program php.
1. Source code untuk membuat index .<!DOCTYPE HTML>
<html>
<head>
<title>Input Data Diri</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="css/style2.css">
</head>
<body id="page">
<div id="kepala"> <img src="unigha.jpg" width="100%" height="170" border="0"> </div>
<div id="pad"> <ul id="menu">
<hr><li id="home"><a href="index.php?menu=utama"><b>Home</b></a></li>
<li id="single"><a href="index.php"><b>Input Data Diri</b></a></li>
<li id="dropdown"><a href="tampildatadiri.php"><b>Tabel Data</b></a></li>
<li id="dropdown"><a href="index.php?menu=about"><b>About</b></a></li>
</ul></div>
<?php
ini_set('display_errors',0);
include "FormBiodata.php";
$formbiodata=new FormBio(); //Kelas yang ada pada file FormBiodata.php
include "SimpanData.php";
$simpan=new Simpan(); //Kelas yang ada pada file SimpanData.php
include "koneksi.php";
$konek=new KonekDb(); //Kelas yang ada pada file Koneksi.php
$menu=$_GET['menu'];
switch ($menu)
{
case 'edit':include "edit.php";break;
case 'delete':include "delete.php";break;
case 'about':include "about.php";break;
case 'utama':include "utama.php";break;
case "SaveData";
$konek->koneksi(); //method yang terdapat pada Class
$simpan->SaveData($nim,$nama,$alamat,$jk,$ttl,$hobi,$email); //Method yang terdapat pada Class Simpan
break;
default:
$formbiodata->CreateForm(); //method yang terdapat pada class FormBio
echo "<hr>";
echo "<center><font size=4><a href='index.php?menu=utama'>Back</a></font></center>";
echo "<center><font color='white' size=4><i>©Created by Rahmat Yani Teknik Informatika <br> Universitas Jabal Ghafur Sigli 2015</center></font>";
}
?>
</body>
</html>
1. 2. Source code untuk membuat form input data
<head>
<title>input mahasiswa</title>
</head>
<body bgcolor='grey'>
<?php
class formbio{ //kelas formbio
function CreateForm(){//method createform untuk membuat form dengan perintah PHP
echo "<center><font size=5 color='white'>Form Input Biodata</font></center>";
echo "<hr>";
echo "<center>";
echo "<form name='form1' method='post' action='Index.php?menu=SaveData'>";
echo "<table width='393' border='0' class='features-table'><tr><th colspan='3' bgcolor='#cccccc' scope='col'>";
echo "Form Input Biodata Diri";
echo "</th></tr>";
echo "<tr bgcolor='666666'><td width='168'>";
echo "Nomor Induk Mahasiswa</span></td>";
echo "<td width='209' colspan='2' align='left' valign='middle'>";
echo "<input type='text' name='nim' /></td></tr>";
echo "<tr bgcolor='#666666'><td width='168'>Nama</td><td width='209' colspan='2'>";
echo "<input type='text' name='nama' /></td></tr>";
echo "<tr bgcolor='#666666'><td width='168'>Alamat</td><td width='209' colspan='2'>";
echo "<textarea name='alamat' /></textarea></td></tr>";
echo "<tr bgcolor='#666666'><td width='168'>Jenis Kelamin</td><td width='209' colspan='2'>";
echo "<select name='jk'><option value='pria'>pria</option><option value='wanita'>wanita</option></select></td></tr>";
echo "<tr bgcolor='#666666'><td width='168'>Tempat & Tgl Lahir</td><td width='209' colspan='2'>";
echo "<input type='text' name='ttl'/></td></tr>";
echo "<tr bgcolor='#666666'><td width='168'>Hobi</td><td width='209' colspan='2'>";
echo "<input type='text' name='hobi'/></td></tr>";
echo "<tr bgcolor='#666666'><td width='168'>Alamat Email</td><td width='209' colspan='2'>";
echo "<input type='text' name='email'/></td></tr>";
echo "<tr><td colspan='3' bgcolor='#cccccc'>";
echo "<div align='center'><input type='submit' name='Submit' value='Simpan'/><input type='reset' name='Reset' value='Batal'/>";
echo "<a href='TampilDataDiri.php'><input type='button' name='Submit2' value='Lihat Data'/></a>";
echo "</td></tr></table>";
}
}
?>
</body>
1. 3.Source code untuk menyimpan data
<?php
$nim=$_POST['nim'];
$nama=$_POST['nama'];
$alamat=$_POST['alamat'];
$jk=$_POST['jk'];
$ttl=$_POST['ttl'];
$hobi=$_POST['hobi'];
$email=$_POST['email'];
class Simpan{ //Kelas Simpan yang memiliki methode SaveData yang berfungsi untuk menyimpan Data pada database
function SaveData($nim,$nama,$alamat,$jk,$ttl,$hobi,$email){
if($nim==""||$nama==""||$alamat==""||$jk==""||$ttl==""||$hobi==""||$email=="") //Validasi ketika isian belum terisi
{
echo "<script>alert('Isian Belum Lengkap');location.href='Index.php';</script>";
}
else
{
mysql_query("insert into datadiri(Nim,Nama,Alamat,jk,ttl,hobi,email) values('$nim','$nama','$alamat','$jk','$ttl','$hobi','$email')");
echo "<script>alert('Data Telah Tersimpan');location.href='Index.php';</script>";
}
}
}
?>
1. 4. Source code untuk menampilkan data
<html>
<head>
<title>Tabel Data Diri</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/style2.css">
</head>
<body bgcolor='grey'>
<?php
include "koneksi.php"; //Menyisipkan File Koneksi.php
$conn=new KonekDb(); //Membuat Objek $conn yang mengacu pada Class Konekdb
$conn->koneksi(); //memanggil method koneksi yang ada pada Class Konekdb
class Tampil{ //Membuat Kelas Tampil
function TampilData(){ //Method TampilData
$query=mysql_query("Select * from datadiri");
echo "<font color='#cccccc' size=6 face='arial'><center>Show Data Diri</center></font><br></br>";
echo "<hr>";
echo "<table border='1' align='center' width=70% class='features-table2'>";
echo "<tr bgcolor='#cccccc' align='center'>";
echo "<td>Nim</td>";
echo "<td>Nama</td>";
echo "<td>Alamat</td>";
echo "<td>Jenis Kelamin</td>";
echo "<td>Tempat & Tanggal Lahir</td>";
echo "<td>Hobi</td>";
echo "<td>Email</td>";
echo "<td>Action</td>";
echo "</tr>";
while($data=mysql_fetch_array($query))
{
echo "<tr align='center'>";
echo "<td>".$data[0]."</td>";
echo "<td>".$data[1]."</td>";
echo "<td>".$data[2]."</td>";
echo "<td>".$data[3]."</td>";
echo "<td>".$data[4]."</td>";
echo "<td>".$data[5]."</td>";
echo "<td>".$data[6]."</td>";
echo "<td><a href='index.php?menu=edit&nim=<?php echo &nim?>'>Edit</a> |
<a href='index.php?menu=delete&nim=<?php echo &nim?>'>Hapus</a></td>";
echo "</tr>";
}
echo "</table>";
echo "<center><font size=4><a href='Index.php'>Back</a></font></center>";
echo "<hr>";
echo "<font color='white' size=3 face='arial'><i><center>©Created by Rahmat Yani Teknik Informatika <br> Universitas Jabal Ghafur Sigli 2015</center></font><br></br>";
}
}
$tampil=new Tampil(); //Membuat Objek $tampil
$tampil->TampilData(); //Memanggil Method TampilData
?>
</body>
</html>
1. Membuat database biodata dan tabel tadadiri.
sip buat bahan kuliah gaaann
ReplyDeleteiya gan sering sering mampir coy
ReplyDeletecodingnya tidak lengkap ?
ReplyDelete• I very much enjoyed this article. Nice article thanks for given this information. I hope it useful to many People DATA SINCE Online Training HYDERABAD
ReplyDelete