<?php
//variabel database
$nama_host="localhost";
$user_db="root";
$password_db="";
$nama_db="db_siswa";
//koneksi database
$koneksi=mysql_connect($nama_host,$user_db,$password_db);
//bila terkoneksi
if($koneksi){
//pilih database
mysql_select_db($nama_db);
}else{
echo "Database tidak terkoneksi";
}
?>
|
<html>
<head>
<title>CRUD Dengan PHP </title>
<style type="text/css">
.labelfrm{
display:block;
font-size:small;
margin-top:5px;
}
.error{
font-size:small;
color:red;
}
</style>
</head>
<body>
<table align="center">
<h1>Data Mahasiswa</h1>
<form action="input.php" method="post" id="frm">
<label for="nis" class="labelfrm">NIS : </label>
<input type="text" name="nis" id="nis" maxlength="10" class="required" size="15"/>
<label for="nama" class="labelfrm" >NAMA : </label>
<input type="text" name="nama" id="nama" size="30" class="required"/>
<label for="alamat" class="labelfrm">ALAMAT : </label>
<textarea name="alamat" id="alamat" cols="40" rows="4" class="required"></textarea>
<label for="submit" class="labelfrm"> </label>
<input type="submit" name="input" value="Simpan" id="input"/>
<input type="reset" name="clear" value="clear" id="clear"/>
</form>
<br><br>
<a href="data.php">Lihat Data</a>
</table>
</html>
|
<?php
include "koneksi.php";
$nis = $_POST['nis'];
$nama = $_POST['nama'];
$alamat = $_POST['alamat'];
$simpan = mysql_query("Insert Into tb_siswa values('$nis','$nama','$alamat')");
header('location:data.php');
?>
|
<?php
include "koneksi.php";
$query=mysql_query("select * from tb_siswa");
$jumlah=mysql_num_rows($query);
echo "Jumlah data ada : ".$jumlah;
?>
<table border="1" cellspacing="0">
<tr>
<th>Nis</th>
<th>Nama</th>
<th>ALamat</th>
<th>Aksi</th>
</tr>
<?php
while($row=mysql_fetch_array($query)){
?>
<tr>
<td><?php echo $row['nis'];?></td>
<td><?php echo $row['nama'];?></td>
<td><?php echo $row['alamat'];?></td>
<td>
<a href="delete.php?nis=<?php echo $row['nis']; ?>" onclick="return confirm('Apakah anda
yakin?')"><img src="button-cross.gif" width="20" height="20" /></a>
<a href="update.php?nis=<?php echo $row['nis']; ?>"><img src="button-edit.gif" width="20" height="20" /></a>
</td>
<?php
}
?>
</table><br />
<a href="index.php">Tambah Data</a><br><br>
|
<?php
include "koneksi.php";
$nis=$_GET['nis'];
$query=mysql_query("delete from tb_siswa where nis='$nis'");
if($query){
?><script language="javascript">document.location.href="data.php";</script><?php
}else{
echo "gagal hapus data";
}
?>
|
<?php
include "koneksi.php";
$nis=$_GET['nis'];
$query=mysql_query("select * from tb_siswa where nis='$nis'");
?>
<form action="simpan.php" method="post">
<table border="1">
<?php
while($row=mysql_fetch_array($query)){
?>
<input type="hidden" name="nis" value="<?php echo $nis;?>"/>
<tr>
<td>Nama</td><td><input type="text" name="nama" value="<?php echo $row['nama'];?>" /></td>
</tr>
<tr>
<td>Alamat</td>
<td><textarea cols="20" rows="5" name="alamat"><?php echo $row['alamat'];?></textarea></td>
</tr>
<tr><td><input type="submit" value="Simpan" name="simpan" /></td>
</tr>
<?php
}
?>
</table>
</form>
|
<?php
include "koneksi.php";
$id=$_POST['nis'];
$nama=$_POST['nama'];
$alamat=$_POST['alamat'];
$query=mysql_query("update tb_siswa set nama='$nama', alamat='$alamat' where nis='$id'");
if($query){
header ('location:data.php');
?> php
}else{
echo "Gagal update data";
echo mysql_error();
}
?>
|