Tugas-01 Pemrograman Web Dinamis

–  Koneksi.php

<?php

mysql_connect(“localhost”,”root”,””);

mysql_select_db(“dika11018028”);

?>

 

-Form_isi

<?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>”;

?>

Image

 

 

-Simpan_data

<?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>”;

}

?>

 

 

-Edit_data

<?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>”;

}

?>

Image

 

-Daftar_data

<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>

Image

 

 

-Hapus_data

<?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>

Image

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