1. Buat database dengan nama biodata.
Kemudian buat tabel dengan nama mahasiswa dengan data berikut:
Pembuatannya
seperti dibawah ini :
22. Kode – kode script pada webnya
Top.php
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled
Document</title>
<style
type="text/css">
body
{
background-color: #CF3;
}
body
{
font-weight: bold;
text-align: center;
font-size: 36px;
}
</style>
</head>
<body>
BIODATA
MAHASISWA UNMUS
</body>
</html>
Left.php
<title>Untitled
Document</title>
<style
type="text/css">
<!--
.style1
{font-family: "Times New Roman", Times, serif}
body
{
background-color: #F39;
font-size: 14px;
}
-->
</style>
</head>
<body>
<a
href="input.php"
target="mainFrame">Input</a><br>
<a
href="tampil.php" target="mainFrame">Tampil</a><br>
<a
href="edit.php" target="mainFrame">Edit</a>
<p> </p>
<p> </p>
</body>
</html>
Index.php
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled
Document</title>
</head>
<frameset
rows="115,*" cols="*" frameborder="yes"
border="2" framespacing="2">
<frame src="top.php"
name="topFrame" scrolling="No"
noresize="noresize" id="topFrame"
title="topFrame" />
<frameset rows="*"
cols="143,*" framespacing="2" frameborder="yes"
border="2">
<frame src="left.php"
name="leftFrame" scrolling="No"
noresize="noresize" id="leftFrame"
title="leftFrame" />
<frame src="input.php"
name="mainFrame" id="mainFrame" title="mainFrame"
/>
</frameset>
</frameset>
<noframes><body>
</body>
</noframes></html>
Input.php
<head>
<title>Untitled
Document</title>
</head>
<body>
<h1
align="center">Form Isian Mahasiswa</h1>
<form
action="aksi.php" method="post" name="form1"
id="form1">
<table>
<tr>
<td>NPM</td>
<td><input
type="text" name="npm" id="npm" /></td>
</tr>
<tr>
<td>Nama</td>
<td><input
type="text" name="nama" id="nama"
/></td>
</tr>
<tr>
<td>Jenis
Kelamin</td>
<td>
<input
type="radio" name="jk" value="Laki-Laki" />
Laki-Laki</br>
<input
type="radio" name="jk" value="Perempuan" />
Perempuan</td>
</tr>
<tr>
<td>Agama</td>
<td>
<select
name="agama">
<option
value="Islam">Islam</option>
<option
value="Kristen">Kristen</option>
<option
value="Katolik">Katolik</option>
<option
value="Hindu">Hindu</option>
<option
value="Budha">Budha</option>
</select>
<label></label></td>
</tr>
<tr>
<td>Apakah
Anda</td>
<td>
<input
type="checkbox" name="ket[]" value="penyakit
keras"
/>
Berpenyakit
Keras</br>
<input
type="checkbox" name="ket[]" value="buta warna"
/>
Buta
Warna</br>
<input
type="checkbox" name="ket[]"
value="berkacamata"
/>
Berkacamata</br></td>
</tr>
<tr>
<td>Alamat</td>
<td><textarea
name="alamat"></textarea></td>
</tr>
<tr>
<td>
<input
type="submit" name="simpan" value="Simpan"
/></td>
<td><input
type="reset" name="reset" value="Reset"
/></td>
</tr>
</table>
</form>
</body>
</html>
Tampil_mhs.php
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled
Document</title>
</head>
<body>
<table width="881"
border="0" align="center" cellpadding="2"
cellspacing="1" bgcolor="#000000" celpading="2"
celspacing="1" >
<tr
bgcolor="#CCFFFF">
<td width="90"><div
align="center"><strong>Npm</strong></div></td>
<td width="125"><div
align="center"><strong>Nama</strong></div></td>
<td width="127"><div
align="center"><strong>Jenis
kelamin</strong></div></td>
<td width="146"><div
align="center"><strong>Agama<strong></div></td>
<td
width="199"><div
align="center"><strong>Penyakit</strong></div></td>
<td
width="163"><div
align="center"><strong>Alamat</strong></div></td>
</tr>
<?php
mysql_connect('localhost','root','');
mysql_select_db('biodata');
$tampil="SELECT * FROM
mahasiswa";
$qryTampil=mysql_query($tampil);
while
($r=mysql_fetch_array($qryTampil))
{
$nis++
?>
<tr
bgcolor="#FFFFFF">
<td
height="28"><?php echo $r['npm']; ?></td>
<td><?php echo $r['nama'];
?></td>
<td><?php echo $r['jk'];
?></td>
<td><?php echo $r['agama'];
?></td>
<td><?php
echo $r['ket']; ?></td>
<td><?php
echo $r['alamat']; ?></td>
</tr>
<?php } ?>
</table>
</body>
</html>
Edit_mhs.php
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled
Document</title>
</head>
<body>
<table width="1012"
border="0" align="center" cellpadding="2"
cellspacing="1" bgcolor="#000000" celpading="2"
celspacing="1" >
<tr
bgcolor="#CCFFFF">
<td width="90"><div
align="center"><strong>NPM</strong></div></td>
<td width="125"><div
align="center"><strong>Nama</strong></div></td>
<td width="127"><div
align="center"><strong>jenis
Kelamim</strong></div></td>
<td width="146"><div
align="center"><strong>agama</strong></div></td>
<td
width="199"><div align="center"><strong>Penyakit</strong></div></td>
<td
width="163"><div
align="center"><strong>alamat</strong></div></td>
<td width="126">
<div align="center"><strong>action
</strong></div></td>
</tr>
<?php
mysql_connect('localhost','root','');
mysql_select_db('biodata');
$tampil="SELECT * FROM
mahasiswa";
$qryTampil=mysql_query($tampil);
while
($r=mysql_fetch_array($qryTampil))
{
$nis++
?>
<tr
bgcolor="#FFFFFF">
<td
height="28"><?php echo $r['npm']; ?></td>
<td><?php echo $r['nama'];
?></td>
<td><?php echo $r['jk'];
?></td>
<td><?php echo $r['agama'];
?></td>
<td><?php
echo $r['ket']; ?></td>
<td><?php
echo $r['alamat']; ?></td>
<td><div
align="center"><a href="delete.php?id=<?php echo
$r['npm'] ; ?>"> |Delete</a> |
<a
href="edit.php?id=<?php echo $r['npm']; ?>">Edit
</a>|</div></td>
</tr>
<?php } ?>
</table>
</body>
</html>
Edit.php
<title>Untitled
Document</title>
</head>
<body>
<div
align="center">
<p>EDIT DATA</p>
<form id="form1"
name="form1" method="post"
action="aksi_edit.php">
<table>
<tr>
<?php
include "aksi.php";
$sqlTampil="SELECT * FROM
mahasiswa Where npm='$_GET[id]'";
$qryTampil=mysql_query($sqlTampil);
$dataTampil=mysql_fetch_array($qryTampil);
?>
<td>NPM</td>
<td><input
name="npm" type="text" id="npm"
value="<?php echo $dataTampil['npm']; ?>" /></td>
</tr>
<tr>
<td>Nama</td>
<td><input
name="nama" type="text" id="nama"
value="<?php echo $dataTampil['nama']; ?>" /></td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td><input name="jk"
type="radio" value="Laki-Laki" onclick="updateTotal();"
/>
Laki-Laki</br>
<input type="radio"
name="jk" value="Perempuan" onclick="updateTotal();" />
Perempuan</td>
</tr>
<tr>
<td>Agama</td>
<td><select
name="agama">
<?php
if
($data['agama'] == "Islam") echo "<option value='Islam'
selected>Islam</option>";
else echo
"<option value='Islam'>Islam</option>";
if ($data['agama'] ==
"Kristen") echo "<option value='Kristen' selected>Kristen</option>";
else echo
"<option value='Kristen'>Kristen</option>";
if ($data['agama'] ==
"Katolik") echo "<option value='Katolik'
selected>Katolik</option>";
else echo
"<option value='Katolik'>Katolik</option>";
if ($data['agama']
== "Hindu") echo "<option value='Hindu'
selected>Hindu</option>";
else echo
"<option value='Hindu'>Hindu</option>";
if ($data['agama'] == "Budha") echo
"<option value='Budha' selected>Budha</option>";
else echo
"<option value='Budha'>Budha</option>";
?>
</select>
<label></label></td>
</tr>
<tr>
<td>Apakah Anda</td>
<td><input
type="checkbox" name="ket[]" value="Berpenyakit
Keras" <?php if($status == "Berpenyakit Keras") echo
'checked="checked"'; ?> />
Berpenyakit Keras</br>
<input type="checkbox"
name="ket[]" value="Buta Warna" <?php if($status ==
"Buta Warna") echo 'checked="checked"'; ?> />
Buta Warna</br>
<input type="checkbox"
name="ket[]"
value="Berkacamata"
<?php if($status == "Berkacamata") echo
'checked="checked"'; ?> />
Berkacamata</br></td>
</tr>
<tr>
<td>Alamat</td>
<td><textarea
name="alamat" value="alamat" onclick="updateTotal();"></textarea></td>
</tr>
<tr>
<td> </td>
<td><label>
<input type="submit"
name="Submit" value="Update" />
</label></td>
</tr>
</table>
</form>
<p> </p>
</div>
</body>
</html>
Aksi.php
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<title>Untitled
Document</title>
</head>
<body>
<?php
mysql_connect("localhost","root","");
$konek=mysql_select_db("biodata");
$npm
= $_POST['npm'];
$nama
= $_POST['nama'];
$jk =
$_POST['jk'];
$agama
= $_POST['agama'];
$ket;
if(count($_POST['ket'])
!= 0){
foreach($_POST['ket']
as $pilihan){
$ket.=$pilihan
. ", ";
}
}else
{
$ket="Tidak
Memilih";
}
$alamat
= $_POST['alamat'];
$input=
"insert into mahasiswa(npm,nama,jk,agama,ket,alamat)values ('$npm',
'$nama', '$jk', '$agama', '$ket', '$alamat')";
$hasil=
mysql_query($input);
if($hasil)
{
echo
"Input data sukses<br>";
}
else
{
echo
"Input data gagal<br>";
}
?>
</body>
</html>
Aksi_edit.php
<title>Untitled
Document</title>
</head>
<body>
<?php
mysql_connect('localhost','root','');
mysql_select_db('biodata');
$update="UPDATE mahasiswa
SET
npm='$_POST[npm]',
nama='$_POST[nama]',
jk='$_POST[jk]',
agama='$_POST[agama]',
ket='$_POST[ket]'
WHERE npm='$_POST[npm]'";
mysql_query($update);
echo "<center>Data
Berhasil Di Update<center>";
echo
"<center><h3><a href=tampil_mhs.php>Lihat
Data</a></h3></center>";
?>
</body>
</html>
Delete.php
<head>
<meta
http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled
Document</title>
</head>
<body>
<?php
mysql_connect('localhost','root','');
mysql_select_db('biodata');
$id=$_GET['id'];
$sql="delete
FROM mahasiswa Where npm='$id'";
$result=mysql_query($sql);
if
($result)
{
echo " proses hapus data berhasil
";
echo "<a
href='tampil_mhs.php'>lihat data</a></div>";
}
else
{
echo "proses hapus data gagal";
echo "<a href='edit_mhs.php'>lihat
data</a></div>";
}
?>
</body>
</html>
3.
3. Ketikan alamat localhost/belajar pada
browser maka akan tampil Form input
4. 4. Tampilan
data yang pernah diinputkan
5.
5. Tampilan edit data
6. 6. Tampilan
data setelah di edit
Tidak ada komentar:
Posting Komentar