background img

The New Stuff

Tugas Pemrograman Web Dinamis Database ARIEF NUR PUTRANTO 11018003

Nama : Arief Nur Putranto
Nim    : 11018003

< SCRIPT koneksi.php >

<?php
mysql_connect("localhost","root","");
mysql_select_db("arief11018003");
?>

< SCRIPT form_isi.php >

<?php
echo "<p align='center'>Tambah Data Penyakit</p>";
echo "<form method='post' action='simpan_data.php'>";
echo "<table>
<tr>
<td width=150>Kode Penyakit</td>
<td><input type='text' name='kode' size=4></td>
</tr>
<tr><td>Nama Penyakit</td>
<td><input type='text' name='nama' size=40></td>
</tr>
<tr><td valign='middle'>Definisi Penyakit </td>
<td><textarea name='definisi' cols=40 rows=6></textarea></td>
</tr>
<tr><td colspan=2 align='center'><input type='submit' value='OK'></td>
</tr>";
echo "</table></form>";
?>

Hasilnya :



< SCRIPT simpan_data.php >

<?php
include "koneksi.php";
$kode = $_POST['kode'];
$nama = $_POST['nama'];
$definisi= $_POST['definisi'];

$query = "insert into penyakit (`kode`,`nama`,`definisi`)
values ('$kode','$nama','$definisi')";
$hasil = mysql_query($query) or die(mysql_error());
if($hasil)
{
echo "<h3 align='center'>Pengiriman Data Sukses !</h3>";
} else {
echo "<h3 align='center'>Pengiriman Data Gagal !
<input type=button value=BACK
OnClick=self.history.back();></h3>";
}
?>

Hasilnya :


< SCRIPT daftar_data.php >

<table border="1" width="550"
align="center">
<tr>
<td height=20 align="center"
width=50><b>Kode</b></td>
<td align="center"
width=200><b>Nama
Penyakit</b></td>
<td align='center'
width=300><b>Definisi</b></td
>
</tr>
<?php

include "koneksi.php";
$qdata = mysql_query("select
kode,nama,definisi from
penyakit");
while($rdata =
mysql_fetch_array($qdata))
{
$kode = $rdata["kode"];
$nama = $rdata["nama"];
$definisi = $rdata["definisi"];
echo "<tr><td
align='center'>$kode</td>
<td>$nama</td>
<td>$definisi</td></tr>";
} ?>
</table>

Hasilnya :


< SCRIPT edit_penyakit.php >

<?php

 include "koneksi.php"; ?>
<table border="1" width="550" align="center">
<tr> <td height=20 align="center"
width=50><b>Kode</b></td>
<td align="center" width=170><b>Nama
Penyakit</b></td>
<td align='center' width=250><b>Definisi</b></td>
<td align='center' width=80><b>Fungsi</b></td>
</tr>
<?php


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


$kode = $_POST['kode'];
$nama = $_POST['nama_penyakit'];
$definisi= $_POST['definisi'];

$query3 = "update penyakit set
kode='$kode',
nama='$nama', definisi='$definisi'
where kode='$kode'";
mysql_query($query3);
}
$i=0;
$qdata = mysql_query("select kode,nama,definisi
from penyakit order by kode");
while($rdata = mysql_fetch_array($qdata))
{
$pkode = $rdata["kode"];
$pnama = $rdata["nama"];
$pdefinisi = $rdata["definisi"];
echo "<tr><td align='center'>$pkode</td><td
>$pnama</td>
<td>$pdefinisi</td><td align='center'>
<a
href='edit_penyakit.php?kode=$pkode&edit=1'>
Edit</a></td> </tr>";
$i++;
} ?>
</table>

<?php

 if(isset($_GET['edit']))
{
$kode = $_GET['kode'];
$qdata2 = mysql_query("select kode, nama,
definisi from penyakit where
kode='$kode'");
while($rdata2 =
mysql_fetch_array($qdata2))
{
$nama2 = $rdata2["nama"];
$definisi2 = $rdata2["definisi"];
}
echo "<p align='center'>Ubah Data
Penyakit <br><br>";
echo "<form method='post'
action='edit_penyakit.php'>
<input type='hidden' name='kode'
value='$kode'>
<input type='hidden' name='kirim_edit'
value=1>";
echo "<table border=0 width=500
align='center'>";
echo "<tr><td width=150>Kode
Penyakit </td> <td><input type='text'
name='kode_penyakit' size=4
value='$kode'></td> </tr>
<tr><td>Nama Penyakit </td>
<td><input type='text'
name='nama_penyakit' size=40
value='$nama2'></td></tr>
<tr><td valign='middle'>Definisi Penyakit
</td>
<td><textarea name='definisi' cols=40
rows=6>$definisi2</textarea></td></tr>
<tr><td colspan=2 align='center'><input
type='submit' value='EDIT'></td></tr>";
echo "</table></form></p>";
}
?>

Hasilnya :


< SCRIPT hapus_penyakit.php >

<?php
 include "koneksi.php"; ?>
<table border="1" width="550"
align="center">
<tr> <td height=20 align="center"
width=50><b>Kode</b></td>
<td align="center" width=170><b>Nama
Penyakit</b></td>
<td align='center'
width=250><b>Definisi</b></td>
<td align='center'
width=80><b>Fungsi</b></td> </tr>
<?php

$hapus = 0;
if(!empty($_GET['hapus'])){
$hapus = $_GET['hapus'];
$kode = $_GET['kode'];
}
if($hapus==1)
{
$query2 = "delete from penyakit where
kode='$kode'";
mysql_query($query2);
}
$qdata = mysql_query("select
kode,nama,definisi from penyakit order by
kode");
$i =0;
while($rdata = mysql_fetch_array($qdata))
{
$pkode = $rdata["kode"];
$pnama = $rdata["nama"];
$pdefinisi = $rdata["definisi"];
echo "<tr><td
align='center'>$pkode</td><td
>$pnama</td>
<td>$pdefinisi</td><td
align='center'>
<a
href='hapus_penyakit.php?kode=$pkode
&hapus=1'>Hapus</a></td> </tr>";
$i++;
} ?>

</table>

Hasilnya Sebelum dihapus :


Hasilnya sesudah dihapus :





0 comments:

Post a Comment

New

Popular Posts