Membuat web dengan database sesuai ketentuan :
1.
Membuat
Database
CREATE DATABASE db_parktikum
CREATE TABLE tb_mhs (
nbi INT(10) NOT NULL,
nama VARCHAR(20) NOT NULL,
kelas VARCHAR(30) NOT NULL,
alamat VARCHAR(30) NOT NULL
);
2.
Membuat
php
index.php
<!doctype
html>
<html>
<head>
<meta
charset="utf-8">
<title>PRAKTIKUM
DASKOM</title>
</head>
<body>
<table
width="50%" border="1" cellspacing="0"
cellpadding="10" align="center">
<tr>
<th
bgcolor=blue><center><h2>SELAMAT
DATANG<h2></center></th></tr>
<tr><td><center><a
href="input_data_mahasiswa.php">1. INPUT DATA
MAHASISWA</a></center></td></tr>
<tr><td><center><a
href="lihat_data_mahasiswa.php">2. LIHAT DATA
MAHASISWA</a></center></td></tr>
<tr
bgcolor=blue><td><center><strong>Coopyright©</strong>Cahyo
Sasmito</center></td></tr>
</table>
</body>
</html>
Input_data_mahasiswa.php
<!doctype
html>
<html>
<head>
<title>FOrm
Praktikum</title>
<link
href="style.css" type="text/css"
rel="stylesheet">
</head>
<body>
<tr>
<center><h2>INPUTKAN DATA
ANDA<h2></center></tr>
<table align="center">
<form
action="simpan.php" method="POST">
<tr>
<td>nbi</td>
<td>:</td>
<td><input
type="text" name="nbi"
maxlength="30"></td></tr>
<tr>
<td>nama</td>
<td>:</td>
<td><input
type="text" name="nama"
maxlength="30"></td></tr>
<tr>
<td>Kelas</td>
<td>:</td>
<td><input
type="text" name="kelas"
maxlength="30"></td></tr>
<tr>
<td>Alamat</td>
<td>:</td>
<td><input
type="text" name="alamat"
maxlength="30"></td></tr>
<tr>
<td></td><td></td>
<td><input
type="submit" value="Simpan"> <input
type="reset" value="Batal"></td>
</form>
</table>
<a
href="lihat_data_mahasiswa.php"> Lihat Data</a>
<a
href="index.php">KEMBALI</center>
</body>
</html>
simpan.php
<?php
include
"koneksi.php";
$nbi=$_POST['nbi'];
$nama=$_POST['nama'];
$kelas=$_POST['kelas'];
$alamat
= $_POST['alamat'];
$query_insert
= "insert into tb_mhs(nbi,nama,kelas,alamat)
values('$nbi','$nama','$kelas','$alamat');";
$insert
= mysql_query($query_insert);
if($insert){
echo"<script>alert('Sukses')</script>)";
include("input_data_mahasiswa.php");
}
else{
echo
"Gagal update ... ";
}
?>
Lihat_data_mahasiswa.php
<html>
<head>
<title>LAYANAN
UTAMA</title>
<link
href="style.css" style="stylesheet"
type="text/css";>
</head>
<body>
<tr>
<center><h2>DATA NAMA
PRAKTIKUM<h2></center></tr>
<table
width="70%" border="1" align="center">
<tr>
<th>NBI</th>
<th>NAMA</th>
<th>KELAS</th>
<th>ALAMAT</th>
<th>EKSEKUSI</th>
</tr>
<?php
include
'koneksi.php';
$mysql="SELECT
* FROM tb_mhs";
$myqry=mysql_query($mysql);
$nomor=0;
while
($kolom=mysql_fetch_assoc($myqry)){
$nbi=$kolom['nbi'];
$nama=$kolom['nama'];
$kelas=$kolom['kelas'];
$alamat=$kolom['alamat'];
echo("<tr><td>$nbi</td><td>$nama</td><td>$kelas</td><td>$alamat</td>");
echo("<td><center><a
href=\"edit.php?id=$nbi\">Edit</a>/
<a href=\"hapus.php?id=$nbi\">Hapus</a></center></td>");
}
?> </table>
<center><a
href="input_data_mahasiswa.php">Tambah Data</a>
<a
href="index.php">KEMBALI</center>
</body>
</html>
hapus.php
<?php
include
'koneksi.php';
$mysql=mysql_query("DELETE
FROM tb_mhs where nbi='$_GET[nbi]'");
if
($mysql){
echo
"<script>alert('Data Berhasil Dihapus')</script>";
echo"<meta
http-equiv='refresh' >";
}
else{
echo"<script>alert('Data
Gagagl dihapus')</script>";
}
?>
0 komentar:
Posting Komentar