Web data mahasiswa sederhana, lengkap dengan kode PHP, edit, hapus dan tambah data

  1. Silahkan copy script berikut, Save as : edit.php

<html>
<head>
<title> Simple CRUD by TUTORIAL WEB.NET </title>
</head>
<body>
<h2>Simple CRUD</h2>
<p> <a href=”index.php”> Beranda </a> / <a href=”tambah.php”> Tambah Data </a> </p>
<h3> Edit Data Siswa </h3>
<?php
include(‘koneksi.php’);
$id=$_GET[‘id’];
$show=mysql_query(“SELECT*FROM siswa WHERE siswa_id=’$id'”);
if(mysql_num_rows($show)==0){
echo ‘window.history.back()’;
}else{
$data=mysql_fetch_assoc($show);
}
?>

<form action=”edit_proses.php” method=”post”>
<input type=”hidden” name=”id” value=”<?php echo $id; ?>”>
<table cellpadding=”3″ cellspacing=”0″>
<tr>
<td>NIS</td>
<td>:</td>
<td><input type=”text” name=”nis” value=”<?php echo $data[‘siswa_nis’]; ?>” required></td>
</tr>
<tr>
<td>Nama Lengkap</td>
<td>:</td>
<td><input type=”text” name=”nama” size=”30″ value=”<?php echo $data[‘siswa_nama’]; ?>” required> </td>
</tr>
<tr>
<td>Kelas</td>
<td>:</td>
<td><select name=”kelas” required>
<option value=””> Pilih Kelas </option>
<option value=”X”>
<?php if($data[‘siswa_kelas’]==’X’){ echo ‘selected’;}?>
>X</option>
<option value=”X”>
<?php if($data[‘siswa_kelas’]==’XI’){ echo ‘selected’;}?>
>XI</option>
<option value=”X”>
<?php if($data[‘siswa_kelas’]==’XII’){ echo ‘selected’;}?>
>XII</option>
</select></td>
</tr>
<tr>
<td>Jurusan</td>
<td>:</td>
<td>
<select name=”jurusan” required>
<option value=””>Pilih jurusan </option>
<option value=”Teknik Komputer Jaringan” <?php if($data[‘$siswa_jurusan’]==’Teknik Komputer Jaringan’){echo ‘selected’;}?>>Teknik Jaringan Komputer</option>
<option value=”Multimedia” <?php if($data[‘$siswa_jurusan’]==’Multimedia’){echo ‘selected’;}?>>Multimedia</option>
<option value=”Akuntansi” <?php if($data[‘$siswa_jurusan’]==’Akuntansi’){echo ‘selected’;}?>>Akuntansi</option>
<option value=”Perbankan” <?php if($data[‘$siswa_jurusan’]==’Perbankan’){echo ‘selected’;}?>>Perbankan</option>
<option value=”Pemasaran” <?php if($data[‘$siswa_jurusan’]==’Pemasaran’){echo ‘selected’;}?>>Pemasaran</option>
</select></td>
</tr>
<td>&nbsp;</td>
<td></td>
<td><input type=”submit” name=”simpan” value=”Simpan” /></td>
</tr>
</table>
</form>
</body>
</html>

2. Silahkan copy script berikut, Save as : edit-proses.php

<?php
if(isset($_POST[‘simpan’])){
include(‘koneksi.php’);
$id=$_POST[‘id’];
$nis=$_POST[‘nis’];
$nama=$_POST[‘nama’];
$kelas=$_POST[‘kelas’];
$jurusan=$_POST[‘jurusan’];
$update=mysql_query(“UPDATE siswa SET siswa_nis=’$nis’,siswa_nama=’$nama’,siswa_kelas=’$kelas’,siswa_jurusan=’$jurusan’ WHERE siswa_id=’$id'”) or die (mysql_error());
if($update){
echo ‘Data Berhasil Disimpan!’;
echo'<a href=”edit.php?id=’.$id.'”> KEMBALI </a>’;
}else{
echo’gagal menyimpan data!’;
echo ‘<a href=”edit.php?id=’.$id.'”>kembali</a>’;
}
}else {
echo’window.history.back()’;
}
?>

3. Silahkan copy script berikut, Save as : hapus.php

<?php
if(isset($_GET[‘id’])){
include(‘koneksi.php’);
$id=$_GET[‘id’];
$cek=mysql_query(“SELECT siswa_id FROM siswa WHERE siswa_id=’$id'”) or die (mysql_error());
if(mysql_num_rows($cek)==0){
echo ‘window.history.back()’;
}else{
$del=mysql_query(“DELETE FROM registrasi WHERE siswa_id=’$id'”);
if($del){
echo ‘Data Berhasil Dihapus!’;
echo ‘<a href=”index.php”> KEMBALI </a>’;
}else{
echo’gagal menghapus data!’;
echo'<a href=”index.php”> KEMBALI </a>’;
}
}
}else {
echo’window.history.back()’;
}
?>

4. Silahkan copy script berikut, Save as : index.php

<html>
<head>
<title> simple CRUD by TUTORIAL WEB</title>
</head>
<body>
<h2> simple CRUD </h2>
<p><a href=”index.php”> BERANDA </a>/<a href=”tambah.php”> TAMBAH DATA </a></p>
<h3> DATA SISWA</h3>
<table cellpadding=”5″ cellspacing=”0″ border=”1″>
<tr bgcolor=”#cccccc”>
<th> no.</th>
<th> nis </th>
<th> nama lengkap </th>
<th> kelas</th>
<th> jurusan </th>
<th> opsi </th>
</tr>
<?php
include (‘koneksi.php’);
$query=mysql_query (“SELECT*FROM siswa ORDER BY siswa_nis DESC”) or die (mysql_error());
if(mysql_num_rows($query)==0){
echo ‘<tr><td colspan=”6″> Tidak Ada Data !</td></tr>’;
}else{
$no=1;
while($data=mysql_fetch_assoc($query)){
echo ‘<tr>’;
echo ‘<td>’. $no.'</td>’;
echo ‘<td>’. $data[‘siswa_nis’].'</td>’;
echo ‘<td>’. $data[‘siswa_nama’].'</td>’;
echo ‘<td>’. $data[‘siswa_kelas’].'</td>’;
echo ‘<td>’. $data[‘siswa_jurusan’].'</td>’;
echo ‘<td><a href=”edit.php?id=’.$data[‘siswa_id’].'”> Edit </a>/<a href=”hapus.php?id=’.$data[‘siswa_id’].'” onclick=”return confirm(\’YAKIN?\’)”> Hapus </a></td>’;
echo ‘</tr>’;
$no++;
}
}
?>

5. Silahkan copy script berikut, Save as : koneksi.php

<?php
$host=”localhost”;
$user=”root”;
$pass=””;
$name=”tutorialweb”;
$koneksi=mysql_connect($host,$user,$pass) or die (“koneksi kedatabase gagal”);
mysql_select_db($name,$koneksi)or die (“tidak ada database yang dipilih”);
?>

6. Silahkan copy script berikut, Save as : tambah.php

<html>
<head>
<title> simple CRUD by TUTORIAL WEB</title>
</head>
<body>
<h2> simple CRUD </h2>
<p><a href=”index.php”> BERANDA </a>/<a href=”tambah.php”> TAMBAH DATA </a></p>
<h3> DATA SISWA</h3>
<form action=”tambah-proses.php” method=”POST”>
<table cellpadding=”5″ cellspacing=”0″>
<tr>
<td> nis </td>
<td> : </td>
<td><input type=”text” name= “nis” required</td>
</tr>
<tr>
<td> nama lengkap </td>
<td> : </td>
<td><input type=”text” name= “nama” size=”30″ required</td>
</tr>
<tr>
<td> kelas</td>
<td>:</td>
<td>
<select name=”kelas” required>
<option value=””> Pilih kelas </option>
<option value=”X”>X </option>
<option value=”XI”> XI </option>
<option value=”XII”> XII </option>
</select>
</td>
</tr>
<tr>
<td> jurusan </td>
<td>:</td>
<td>
<select name=”jurusan” required>
<option value=””> Pilih jurusan </option>
<option value=”teknik komputer dan jaringan”> teknik komputer dan jaringan </option>
<option value=”multimedia”> multimedia </option>
<option value=”akuntansi”>akuntansi </option>
<option value=”perbankan”>perbankan </option>
<option value=”pemasaran”>pemasaran </option>
</select>
</td>
</tr>
<tr>
<td><input type=”submit” name=”tambah” value=”TAMBAH”></td>
</tr>
</table>
</form>
</body>
</html>

7. Silahkan copy script berikut, Save as : tambah-proses.php

<?php
if(isset($_POST[‘tambah’])){
include(‘koneksi.php’);
$nis=$_POST[‘nis’];
$nama=$_POST[‘nama’];
$kelas=$_POST[‘kelas’];
$jurusan=$_POST[‘jurusan’];
$input=mysql_query(“INSERT INTO siswa VALUES (NULL,’$nis’,’$nama’,’$kelas’,’$jurusan’)”) or die (mysql_error());
if($input){
echo’Data Berhasil Tambahkan!’;
echo'<a href=”tambah.php”> KEMBALI </a>’;
}else {
echo’data GAGAL di tambahkan!’;
echo'<a href=”tambah.php”> KEMBALI </a>’;
}
}else {
echo ‘window.history.back()’;
}
?>

Silahkan download databasenya

http://www.mediafire.com/download/c81cn3vvw5k6oi5/tutorialweb.sql

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

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

Foto Google

You are commenting using your Google 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 )

Connecting to %s