You are on page 1of 7

Tampilan Data base

Tampilan Data Mahasiswa

Tampilan Tambah Mahasiswa

Tampilan Ubah

KODINGAN:
Koneksi
<?php
$host="localhost";
$user="root";
$pass="";
$database="db_kampus";

$koneksi=mysql_connect($host,$user,$pass) or die ("KONEKSI GAGAL".mysql_error);


mysql_select_db($database,$koneksi) or die ("Database Tidak Ada");
?>
Mahasiswa Baru
<form action="mahasiswa_simpan.php" method="post" enctype="multipart/form-data">
<table border="0" align="center">
<tr>
<th colspan="4" align="center"><h2>Data Mahasiswa</h2></th>
</tr>
<tr>
<td width="111">NIM</td>
<td width="4">:</td>
<td width="213"><input type="text" name="txtnim"></td>
</tr>

<tr>
<td>Nama</td>
<td>:</td>
<td><input type="text" name="txtnama"></td>
</tr>
<tr>
<td>Kelas</td>
<td>:</td>
<td><input type="text" name="txtkelas"></td>
</tr>
<tr>
<td colspan="4" align="center"><input type="submit" value="Simpan"><input type="reset"
value="Batal"> <a href="mahasiswa_tampil.php">Lihat Data Mahasiswa</a></td>
</tr>

</table>
</form>
Mahasiswa ganti
<?php
include "koneksi.php";

$kode=$_GET['kode'];

$query=mysql_query("SELECT * FROM tb_mhs where nim = '$kode'");


$data=mysql_fetch_array($query);
$a=$data['nim'];
$b=$data['nama'];
$c=$data['kelas'];
?>

<form action="mahasiswa_ubah.php" method="post" enctype="multipart/form-data">


<table width="421" border="0" align="center">
<tr>
<td colspan="3"><h2 align="center">Ubah Data </h2></td>
</tr>
<tr>
<td width="77">NIM</td>
<td width="13">:</td>
<td width="317"><?php echo $a;?>
<input type ="hidden" name="txtnim" id="hiddenField" value="<?php echo $a; ?>"/></td>
</tr>
<tr>
<td>Nama</td>
<td>:</td>
<td><input name="txtnama" type="text" id="tetxfield" value="<?php echo $b;?>" size="30"
maxlength="30" /></td>
</tr>
<tr>
<td>Kelas</td>
<td>:</td>
<td><input name="txtkelas" type="text" id="tetxfield" value="<?php echo $c;?>" size="30"
maxlength="30" /></td>
</tr>
<tr>
<td colspan="3"><div align="center">
<input type="submit" name="ubah" id="simpan" value="Simpan" />
<a href="mahasiswa_tampil.php">KEMBALI</a> </div></td>
</tr>

</table>
</form>
Simpan
u<?php
include "koneksi.php";

$a=$_POST['txtnim'];
$b=$_POST['txtnama'];
$c=$_POST['txtkelas'];

if($a=="")
{
echo "<script>window.alert(Isi Data Mahasiswa Dengan Lengkap');
window.location='mahasiswa_baru.php'</script>";
}
else
{
$cari=mysql_query("select * from tb_mhs where nim='$a'");
$data=mysql_fetch_array($cari);

if($data=='$a')
{
echo "<script>window.alert('NIM sudah ada');
window.location='mahasiswa_baru.php'</script>";
}
else
{
mysql_query("insert into tb_mhs values('$a','$b','$c')");

echo "<script>window.alert('Data Mahasiswa Sudah Tersimpan');


window.location='mahasiswa_baru.php'</script>";
}
}
?>
Tampil
<?php
include "koneksi.php";
?>
<h2 align="center">DATA MAHASISWA</h2>
<p align="center"><a href="mahasiswa_baru.php">Tambah Data Mahasiswa</a></p>
<table width="577" border="1" align="center" >
<tr>
<th width="7%" bgcolor="#CCCCCC">No </th>
<th width="20%" bgcolor="#CCCCCC">NIM </th>
<th width="28%" bgcolor="#CCCCCC">Nama</th>
<th width="24%" bgcolor="#CCCCCC">Kelas</th>
<th width="21%" bgcolor="#CCCCCC"><div align="center">Aksi</div></th>
</tr>

<?php
$n=1;
$query=mysql_query("select* from tb_mhs order by nim");
if(mysql_num_rows($query)>0){
while($data=mysql_fetch_array($query)){

?>

<tr>
<td align="center"><?php echo $n; ?></td>
<td align="center"><?php echo $data['nim']; ?></td>
<td align="center"><?php echo $data['nama']; ?></td>
<td align="center"><?php echo $data['kelas'];?></td>
<td align='center'><div align="center"><a href="mahasiswa_ganti.php?kode=<?=$data['nim']?
>">Ubah</a>|
<a href="mahasiswa_hapus.php?kode=<?=$data['nim']?>"
onclick="return confirm('Yakin Anda Akan
Menghapus Data<?=$data['nama']?>?')">Hapus</a></div>
</td>
</tr>

<?php
$n++; }}
?></table>
Ubah
<?php
include "koneksi.php";
$a=$_POST['txtnim'];
$b=$_POST['txtnama'];
$c=$_POST['txtkelas'];
mysql_query("update tb_mhs set nama='$b', kelas='$c' where nim='$a'")or die ("Query
Gagal".mysql_error());
{echo "<script>window.alert('Data Telah Diubah');
window.location='mahasiswa_tampil.php'</script>";}

You might also like