Membuat Aplikasi CRUD sederhana dengan PHP dan Mysql
Pertama kali adalah unduh bootstrap di http://getbootstrap.com/
Coding :
1.formdataguru.php
<!DOCTYPE html>
<html>
<head>
<title>data guru</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<h2>Data Guru</h2>
<?php include ("koneksi.php"); ?>
<form action="#" method="post">
<div class="form-group">
<label for="nama"><b>Nama :</b></label>
<input type="text" class="form-control" name="textnama" placeholder="nama guru">
</div>
<div class="form-group">
<label for="alamat"><b>Alamat :</b></label>
<input type="text" class="form-control" id="alamat" name="textalamat" placeholder="alamat guru">
</div>
<div class="form-group">
<label for="pangkat"><b>Pangkat :</b></label>
<input type="text" class="form-control" id="alamat" name="textpangkat" placeholder="pangkat guru">
</div>
<div class="form-group">
<label for="jabatan"><b>Jabatan :</b></label>
<input type="text" class="form-control" id="alamat" name="textjabatan" placeholder="jabatan guru">
</div>
<input type="submit" name="bok" class="btn btn-success" value="Simpan"></button>
<button class="btn btn-danger" type="reset">Reset</button>
<a href="tampildataguru.php"><h4>tampil data guru
<a href="index.html"><h4>halaman utama
</form>
<?php
if(isset($_POST ['bok'])){
$nama =$_POST['textnama'];
$alamat =$_POST['textalamat'];
$pangkat =$_POST['textpangkat'];
$jabatan =$_POST['textjabatan'];
$q = "insert into data_guru (nama,alamat,pangkat,jabatan)values ('$nama','$alamat','$pangkat','$jabatan')";
//echo $q;
mysql_query($q);
echo "tersimpan";
}
?>
</div>
</body>
</html>
2.formdatasiswa.php
<!DOCTYPE html>
<html>
<head>
<title>data siswa</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<h2>DATA SISWA</h2>
<?php
include ("koneksi.php"); ?>
<form action="#" method="post">
<div class="form-group">
<label for="induk">No Induk :</label>
<input type="text" class="form-control" name="textinduk">
</div>
<div class="form-group">
<label for="nama">Nama :</label>
<input type="text" class="form-control" name="textnama">
</div>
<div class="form-group">
<label for="lahir">Tanggal lahir :</label>
<input type="text" class="form-control" name="textlahir">
</div>
<div class="form-group">
<label for="kelamin">Kelamin :</label>
<class="form-control" name="textkelamin">
<select name="textkelamin" size="1">
<option value="cowok">Laki-laki</option>
<option value="cewek">Perempuan</option>
</select>
</div>
<div class="form-group">
<label for="kelas">Kelas :</label>
<class="form-control" select name="textkelas">
<select name="textkelas" size="1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<input type="submit" name="bok" class="btn btn-success" value="Simpan"></button>
<button class="btn btn-danger" type="reset">Reset</button>
<a href="tampildatasiswa.php"><h4>tampil data siswa
<a href="index.html"><h4>halaman utama
</form>
<?php
if(isset($_POST ['bok'])){
$induk =$_POST['textinduk'];
$nama =$_POST['textnama'];
$lahir =$_POST['textlahir'];
$kelamin =$_POST['textkelamin'];
$kelas =$_POST['textkelas'];
$q = "insert into data_siswa (induk,nama,lahir,kelamin,kelas)values ('$induk','$nama','$lahir','$kelamin','$kelas')";
//echo $q;
mysql_query($q);
echo "Data sudah tersimpan";
}
?>
</div>
</body>
</html>
<body>
</body>
</html>
3.formjadwal.php
<!DOCTYPE html>
<html>
<head>
<title>Jadwal</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<h2>Jadwal</h2>
<?php include ("koneksi.php"); ?>
<form action="#" method="post">
<div class="form-group">
<label for="hari"><b>Hari :</b></label>
<class="form-control" name="texthari" placeholder="hari">
<select name="texthari" size="1">
<option value="Senin">Senin</option>
<option value="Selasa">Selasa</option>
<option value="Rabu">Rabu</option>
<option value="Kamis">Kamis</option>
<option value="Jum'at">Jum'at</option>
</select>
</div>
<div class="form-group">
<label for="nama_guru"><b>Nama Guru :</b></label>
<input type="text" class="form-control" id="alamat" name="textnama_guru" placeholder="masukkan nama guru">
</div>
<div class="form-group">
<label for="mapel"><b>Mata Pelajaran :</b></label>
<class="form-control" id="alamat" name="textmapel">
<select name="textmapel" size="1">
<option value="mapel-001">mapel-001</option>
<option value="mapel-002">mapel-002</option>
<option value="mapel-003">mapel-003</option>
<option value="mapel-004">mapel-004</option>
<option value="mapel-005">mapel-005</option>
<option value="mapel-006">mapel-006</option>
<option value="mapel-007">mapel-007</option>
<option value="mapel-008">mapel-008</option>
</select>
</div>
<div class="form-group">
<label for="kelas"><b>Kelas :</b></label>
<class="form-control" id="alamat" name="textkelas">
<select name="textkelas" size="1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="form-group">
<label for="waktu"><b>Waktu / Jam :</b></label>
<class="form-control" id="alamat" name="textwaktu">
<select name="textwaktu" size="1">
<option value="Jam Pertama">Jam Pertama</option>
<option value="Jam Kedua">Jam Kedua</option>
<option value="Jam Tambahan">Jam Tambahan</option>
</select>
</div>
<div class="form-group">
<label for="ruang"><b>Ruang :</b></label>
<class="form-control" id="alamat" name="textruang">
<select name="textruang" size="1">
<option value="Ruang 1">Ruang 1</option>
<option value="Ruang 2">Ruang 2</option>
<option value="Ruang 3">Ruang 3</option>
<option value="Ruang 4">Ruang 4</option>
<option value="Ruang 5">Ruang 5</option>
<option value="Ruang 6">Ruang 6</option>
<option value="Laboratorium">Laboratorium</option>
</select>
</div>
<input type="submit" name="bok" class="btn btn-success" value="Simpan"></button>
<button class="btn btn-danger" type="reset">Reset</button>
<a href="tampiljadwal.php"><h4>tampil jadwal
<a href="index.html"><h4>halaman utama
</form>
<?php
if(isset($_POST ['bok'])){
$hari =$_POST['texthari'];
$nama_guru =$_POST['textnama_guru'];
$mapel =$_POST['textmapel'];
$kelas =$_POST['textkelas'];
$waktu =$_POST['textwaktu'];
$ruang =$_POST['textruang'];
$q = "insert into jadwal (hari,nama_guru,mapel,kelas,waktu,ruang)values ('$hari','$nama_guru','$mapel','$kelas','$waktu','$ruang')";
//echo $q;
mysql_query($q);
echo "tersimpan";
}
?>
</div>
</body>
</html>
4.formmapel.php
<!DOCTYPE html>
<html>
<head>
<title>mata pelajaran</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<h2>MATA PELAJARAN</h2>
<?php
include ("koneksi.php"); ?>
<form action="#" method="post">
<div class="form-group">
<label for="kode_mapel">Kode Mata Pelajaran :</label>
<class="form-control" name="textkode_mapel">
<select name="textkode_mapel" size="1">
<option value="mapel-001">mapel-001</option>
<option value="mapel-002">mapel-002</option>
<option value="mapel-003">mapel-003</option>
<option value="mapel-004">mapel-004</option>
<option value="mapel-005">mapel-005</option>
<option value="mapel-006">mapel-006</option>
<option value="mapel-007">mapel-007</option>
<option value="mapel-008">mapel-008</option>
</select>
</div>
<div class="form-group">
<label for="mapel">Mata Pelajaran :</label>
<input type="text" class="form-control" name="textmapel">
</div>
<input type="submit" name="bok" class="btn btn-success" value="Simpan"></button>
<button class="btn btn-danger" type="reset">Reset</button>
<a href="tampildatamapel.php"><h4>tampil data mapel
<a href="index.html"><h4>halaman utama
</form>
<?php
if(isset($_POST ['bok'])){
$kode_mapel =$_POST['textkode_mapel'];
$mapel =$_POST['textmapel'];
$q = "insert into data_mapel (kode_mapel,mapel)values ('$kode_mapel','$mapel')";
//echo $q;
mysql_query($q);
echo "Data sudah tersimpan";
}
?>
</div>
</body>
</html>
<body>
</body>
</html>
5.hapusdataguru.php
<!DOCTYPE html>
<html>
<head>
<title>data guru</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<h2>data guru</h2>
<?php
include "koneksi.php";
$nama = $_GET['n'];
$q = "delete from data_guru where nama ='$nama'";
mysql_query($q);
echo "data terhapus\n";
echo "<a href='tampildataguru.php'>kembali .....</a>";
?>
</div>
</body>
</html>
6.hapusdatamapel.php
<!DOCTYPE html>
<html>
<head>
<title>data guru</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<h2>data guru</h2>
<?php
include "koneksi.php";
$kode_mapel = $_GET['n'];
$q = "delete from data_mapel where kode_mapel ='$kode_mapel'";
mysql_query($q);
echo "data terhapus\n";
echo "<a href='tampildatamapel.php'>kembali .....</a>";
?>
</div> </body> </html>
7. hapusdatasiswa.php
<!DOCTYPE html>
<html>
<head>
<title>data guru</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<h2>data siswa</h2>
<?php
include "koneksi.php";
$induk = $_GET['n'];
$q = "delete from data_siswa where induk ='$induk'";
mysql_query($q);
echo "data terhapus\n";
echo "<a href='tampildatasiswa.php'>kembali .....</a>";
?>
</div> </body> </html>
8.hapusjadwal.php
<!DOCTYPE html>
<html>
<head>
<title>data guru</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<h2>jadwal</h2>
<?php
include "koneksi.php";
$hari = $_GET['n'];
$q = "delete from jadwal where hari ='$hari'";
mysql_query($q);
echo "data terhapus\n";
echo "<a href='tampiljadwal.php'>kembali .....</a>";
?>
</div> </body> </html>
9.index.php
<!DOCTYPE html>
<html>
<head>
<title>SI SDN PEKAYON 1 PAGI</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg">
<div class="container">
<div class="jumbotron">
<h1>Sistem Informasi SDN Pekayon 1 Pagi</h1>
<p>
<a href="tampildataguru.php"><button class="btn-link"><h4>Data Guru</h4></button></a>
<a href="tampildatasiswa.php"><button class="btn-link"><h4>Data Siswa</h4></button></a>
<a href="tampildatamapel.php"><button class="btn-link"><h4>Mata Pelajaran</h4></button></a>
<a href="tampiljadwal.php"><button class="btn-link"><h4>Jadwal</h4></button></a>
<a href="pencarian.php"><button class="btn-link"><h4>Pencarian</h4></button></a>;
</p>
</div>
</div>
<div class="">
<p>
<img src="img/unindra.jpg" alt="Mountain View" style="width:685px; height:300px; margin-left:220px; "></br>
<center><embed src="1.mp3" autostart="true" loop="true" hidden="true"></center>
</p>
</div>
<center><font color="green">Copyright @2013</font><font color="blue"> Noviyanto & Nurohman</font><font color="green"> All rights reserved</font></center>
</body>
</html>
10.koneksi.php
<?php
$host = "127.0.0.1";
$user = "root";
$pass = "";
$dbname = 'tugas_web';
$koneksi = mysql_connect($host, $user,$pass );
mysql_select_db($dbname);
//echo "yuhu";
?>
11.pencarian.php
<!DOCTYPE html>
<html>
<head>
<title>pencarian data</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body background="img/1.jpg"><center>
<?php include ("koneksi.php"); ?>
<form action="#" method="post">
<div class="form-group">
</br></br></br>
<label for="nama"><b>Cari Identitas Guru</b></label>
<input type="text" class="form-control" name="textnama">
</div>
<input type="submit" name="bok" class="btn btn-success" value="Cari"></button>
<button class="btn btn-danger" type="reset">Clear</button>
</form>
<?php
if(isset($_POST ['bok']))
{
$nama =$_POST['textnama'];
$q = "select * from data_guru where nama like '%$nama%'";
$result = mysql_query($q); //execute the query $q
echo "<table border='4' cellpadding='5' cellspacing='8'>";
echo "<tr> <td>Nama</td> <td>Alamat</td> <td>Pangkat</td> <td>Jabatan</td> </tr>";
while ($data = mysql_fetch_array($result))
{//fetch the result from query into an array
echo "
<tr>
<td>".$data['nama']."</td>
<td>".$data['alamat']."</td>
<td>".$data['pangkat']."</td>
<td>".$data['jabatan']."</td>
</tr>";
}
echo "</table>";
}
?>
<!-- start pencarian siswa -->
<form action="#" method="post">
<div class="form-group">
</br></br></br>
<label for="nama"><b>Cari Identitas Siswa</b></label>
<input type="text" class="form-control" name="textnama">
</div>
<input type="submit" name="bok" class="btn btn-success" value="Cari"></button>
<button class="btn btn-danger" type="reset">Clear</button>
</form>
<?php
if(isset($_POST ['bok']))
{
$nama =$_POST['textnama'];
$q = "select * from data_siswa where nama like '%$nama%'";
$result = mysql_query($q); //execute the query $q
echo "<table border='4' cellpadding='5' cellspacing='8'>";
echo "<tr> <td>No Induk</td> <td>Nama</td> <td>Tanggal Lahir</td> <td>Jenis Kelamin</td> <td>Kelas</td> </tr>";
while ($data = mysql_fetch_array($result))
{//fetch the result from query into an array
echo "
<tr>
<td>".$data['induk']."</td>
<td>".$data['nama']."</td>
<td>".$data['lahir']."</td>
<td>".$data['kelamin']."</td>
<td>".$data['kelas']."</td>
</tr>";
}
echo "</table>";
}
?>
<a href="index.html"><h4>kembali ke halaman utama
</center></body></html>
untuk demo :
nurohman.esy.es/sdnpekayon
untuk unduh file :
http://www.4shared.com/zip/l46fFd1uce /tugas_web.html
0 Comments