Tugas Pemograman web dinamis

Indeks.php

<html>
<head>
<title>Inputkan data penyakit </title>
</head>
<body>
<center>
<H2> MASUKAN DATA PENYAKIT </H2><br>
<form method="POST" action="proses.php">
<table bgcolor="#FFFF99">
<tr>
<td>Id</td>
<td> : <input type="text" name="id"></td>
</tr>
<tr>
<td>Nama</td>
<td> : <input type="text" name="nama" ></td>
</tr>
<tr>
<td>Alamat</td>
<td> : <input type="text" name="alamat"></td>
</tr>
<tr>
<td>Penyakit</td>
<td>: <input type="text" name="penyakit"></td>
</tr>
<tr>
<td>
<td>
<input type="submit" name="kirim" value="kirim">
<input type="reset" name="batal" value="batal">
</td>
</td>
</tr>
</table>
</form>

</center>
</body>
</html>

Form Awal

View.php

<center>
<table border="3" width="400"><br><br><br/>
<H2> DATA RIWAYAT PENYAKIT </H2><br>
<?php
include"koneksi.php";
$query=mysql_query("select* from penyakit");
$jumlah=mysql_num_rows($query);
echo "jumlah data yang tersedia = ".$jumlah;
?>
<bgcolor="#FFFF99">
<tr align="center">
<td><strong>No</strong></td>
<td><strong>Id</strong></td>
<td><strong>Nama</strong></td>
<td><strong>Alamat</strong></td>
<td><strong>Penyakit</strong></td>
<td><strong>Action</strong></td>
</tr>
<?php
$no=0;
while ($row=mysql_fetch_array($query)) {
?>
<tr>
<td><?php echo $no=$no+1;?></td>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['nama'];?></td>
<td><?php echo $row['alamat'];?></td>
<td><?php echo $row['penyakit'];?></td>
<td>
<a href="delete.php?id=<?php echo $row['id'];?>" onClick="return confirm('Apakah anda yakin ?')">
<input type="submit" name="Delete" value="Delete">
</a>
<a href="edit.php?id=<?php echo $row['id'];?>" onClick="return confirm('anda mengUpdate')">
<input type="submit" name="Edit" value="Edit">
</a>
</td>
</tr>
<?php
}
?>
</center>
</table><tr><td>
<a href="index.php"><input type="submit" name="add files" value="add files"></a></td></tr>
<a href="index.php"><input type="submit" name="cancel files" value="cancel files"></a></td></tr>

form selanjutnya

Update.php

<?php
include "koneksi.php";
$id = $_POST ['id'];
$nama = $_POST ['nama'];
$alamat = $_POST ['alamat'];
$penyakit = $_POST ['penyakit'];
$query = mysql_query("UPDATE penyakit SET id='$id', nama='$nama', alamat='$alamat', penyakit='$penyakit' where id='$id'" );
if($query){
echo "<script> alert('berhasil masuk'); location.href='view.php';</script>";
}else{
echo "<script>alert('gagal masuk');</script>";
}
?>

Delete.php

<?php
include "koneksi.php";
$id=$_GET['id'];
$query=mysql_query("DELETE from penyakit where id='$id'");
if ($query) {
?><script language="javascript">document.location.href="view.php";</script><?php
}else{
echo "anda gagal";
}

?>

Edit.php

<?php
include"koneksi.php";
$id=$_GET['id'];
$query=mysql_query("select* from penyakit where id='$id'");
?>
<form action="update.php" method="post">
<table border="1" width="400">
<?php
while ($row=mysql_fetch_array($query)) {
?>
<input type="hidden" name="id" value="<?php echo $id;?>">
<tr>
<td><strong>Id</strong></td>
<td><input type="text" name="id" value="<?php echo $row['id'];?>"></td>
</tr>
<tr>
<td><strong>Namat</strong></td>
<td><input type="text" name="nama" value="<?php echo $row['nama'];?>"></td>
</tr>
<tr>
<td><strong>Alamat</strong></td>
<td><input type="text" name="alamat" value="<?php echo $row['alamat'];?>"></td>
</tr>
<tr>
<td><strong>Penyakit</strong></td>
<td><input type="text" name="penyakit" value="<?php echo $row['penyakit'];?>"></td>
</tr>
<tr><td>
<td><input type="submit" name="save" value="save" >
<a href="view.php"><input type="reset" name="batal" value="batal"></a></td></td>
</tr>
<?php
}
?>
</table>
</form>

Koneksi.php

<?php
$host="localhost";
$user="root";
$pass="";
$database="dbpenyakit";
$koneksi=mysql_connect($host, $user, $pass);
mysql_select_db($database, $koneksi);
$tanggal=date("Y-m-d");
if($koneksi){
//echo "anda berhasil masuk database";
}
else{
?>
<script type="text/javascript">alert('gagal ke database')</script>
<?php
mysql_error();
}
?>

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s