[trick] Membuat Aplikasi Sederhana Dengan PHP dan ORACLE Bag-2

Bismillah…

OK Kali ini Kita Lanjut Y ke Aplikasi PHP ORACLE bagian kedua yaitu delete,tambah,edit,view data dengan php oracle , hehe >>

bagi yang ketinggalan silahkan lihat bagian pertama dari aplikasi sederhana dengan php oracle

1. siapkan databases >>

data_ora

2. lanjut ke koding y >>

2.1 oracle.php


<?php
$c=oci_connect("root","12345","XE");

echo"Buku Tamu <hr><p></p>";

if($_GET['menu']==''){

echo"<a href='?menu=tambah_data'><input type=submit value='Tambah'></a><p></p>
<table border=1 cellpadding=4 cellspacing=0>
<tr bgcolor='#ccc'><td>Id</td><td>EMail</td><td>Nama</td><td>Pesan</td><td>PASSWORD</td><td>Edit</td><td>Hapus</td></tr>";

$query="select * from bukutamu";

$statmen=oci_parse($c,$query);
oci_execute($statmen,OCI_DEFAULT);

while($data=oci_fetch_array($statmen,OCI_BOTH)){
echo"<tr><td>".$data['ID']."</td><td>".$data['EMAIL']."</td><td>".$data['NAMA']."</td><td>".$data['PESAN']."</td><td>".$data['PASSWORD']."</td><td><a href='?menu=edit&id=$data[ID]'>edit</a></td><td><a href=\"aksi.php?act=hapus_data&id=$data[ID]\" onclick=\"return confirm('Yakin Mau Hapus $data[NAMA]??')\"'>Hapus</a></td></tr>";
}

echo"</table>";

oci_free_statement($statmen);

}if($_GET['menu']=='edit'){
$sql="select * from bukutamu where id='$_GET[id]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
$data=oci_fetch_array($statment);
echo"
<form method=POST action='aksi.php?act=edit_data'>
<input type=hidden name='ID' value='$data[ID]'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>Id</td><td><input type=text name='ID' value='$data[ID]' size=1 disabled></td></tr>
<tr><td>Email</td><td><input type=text name='EMAIL' value='$data[EMAIL]'></td><tr>
<tr><td>Nama</td><td><input type=text name='NAMA' value='$data[NAMA]'></td><tr>
<tr><td>Pesan</td><td><input type=text name='PESAN' value='$data[PESAN]'></td><tr>
<tr><td>Password</td><td><input type=text name='PASSWORD' value='$data[PASSWORD]'></td><tr>
<tr><td></td><td><input type=submit value='Update'></td><tr>
</table>
</form>
";
}

if($_GET['menu']=='tambah_data'){
echo"
<form method=POST action='aksi.php?act=tambah_data'>
<table border=1 cellpadding=4 cellspacing=0>
<tr><td>ID</td><td><input type=text name='ID'></td></tr>
<tr><td>EMAIL</td><td><input type=text name='EMAIL'></td></tr>
<tr><td>NAMA</td><td><input type=text name='NAMA'></td></tr>
<tr><td>PESAN</td><td><input type=text name='PESAN'></td></tr>
<tr><td>PASSWORD</td><td><input type=text name='PASSWORD'></td></tr>
<tr><td></td><td><input type=submit value='SIMPAN'></td><tr>
</table>
</form>
";
}
?>

2.2 aksi.php


<?php
$c=oci_connect("root","12345","XE");

$act=$_GET['act'];

if($act=='edit_data'){
$sql="update bukutamu set EMAIL='$_POST[EMAIL]',NAMA='$_POST[NAMA]',PESAN='$_POST[PESAN]',PASSWORD='$_POST[PASSWORD]' where ID='$_POST[ID]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:oracle.php');
}

if($act=='tambah_data'){
$sql="insert into bukutamu(ID,EMAIL,NAMA,PESAN,PASSWORD)values('$_POST[ID]','$_POST[EMAIL]','$_POST[NAMA]','$_POST[PESAN]','$_POST[PASSWORD]')";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:oracle.php');
}

if($act=='hapus_data'){
$sql="delete from bukutamu where ID='$_GET[id]'";
$statment=oci_parse($c,$sql);
oci_execute($statment,OCI_DEFAULT);
oci_commit($c);
header('location:oracle.php');
}

?>

3. hasilnya sebaga berikut >>

hasil_ora

OK selesai

link download >> http://www.4shared.com/zip/6xGw6m2E/oracle2.html

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: