- Buat database akademik menggunakan phpmyadmin

advertisement
-
Buat database akademik menggunakan phpmyadmin
Buat tabel Mahasiswa dengan struktur berikut:
Buat tampilan form di bawah:
Input_data_mhs.php
Listing form
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="simpan_data.php">
<table width="200" border="1">
<tr>
<td colspan="3"><div align="center">INPUT DATA MAHASISWA </div></td>
</tr>
<tr>
<td width="96">NIM</td>
<td width="3">:</td>
<td width="79"><input name="nim" type="text" id="nim" /></td>
</tr>
<tr>
<td>NAMA</td>
<td>:</td>
<td><input name="nama" type="text" id="nama" /></td>
</tr>
<tr>
<td>KELAS</td>
<td>:</td>
<td><input name="kelas" type="text" id="kelas" /></td>
</tr>
<tr>
<td>JURUSAN</td>
<td>:</td>
<td><input name="jurusan" type="text" id="jurusan" /></td>
</tr>
<tr>
<td><div align="right">
<input type="submit" name="Submit" value="SIMPAN" />
</div></td>
<td> </td>
<td><input type="reset" name="Submit2" value="BERSIH" /></td>
</tr>
</table>
</form>
</body>
</html>
Tampilan simpan_data_mhs
simpan_data_mhs.php
<?php
//listing koneksi ke database
$koneksi=mysql_connect("localhost","root","password")or die("Tidak Bisa Membuka
PhpMyadmin ".mysql_error());
if($koneksi){mysql_select_db("akademik",$koneksi)or die("Database Tidak Dapat Dibuka
".mysql_error());}
$sql=mysql_query("insert into mahasiswa values('$nim','$nama','$kelas','$jurusan')");
if($sql){ ?>
<script>
alert('Data Telah Tersimpan');
</script>
<?php } else { ?>
<script>
alert('Simpan Data Gagal');
</script>
<?php } ?>
<font color="#FF0000" size="5">DATA TELAH TERSIMPAN</font><br>
<a href="lihat_data.php" style="text-decoration:none;"> Lihat Data </a>
Tampilan lihat_data_mhs
Lihat_data_mhs.php
<table border="1">
<tr><th colspan="4">TAMPIL DATA MAHASISWA</th></tr>
<tr><td>NIM</td><td>NAMA MAHASISWA</td><td>KELAS</td><td>JURUSAN</td></tr>
<?php
//listing koneksi ke database
$koneksi=mysql_connect("localhost","root","password")or die("Tidak Bisa Membuka
PhpMyadmin ".mysql_error());
if($koneksi){
mysql_select_db("akademik",$koneksi)or die("Database Tidak Dapat Dibuka ".mysql_error());
}
$tampil=mysql_query("select*from mahasiswa");
while($x=mysql_fetch_array($tampil)){?>
<tr><td><?php echo $x[nim]; ?></td><td><?php echo $x[nama]; ?></td><td><?php echo
$x[kelas]; ?></td><td><?php echo $x[jurusan]; ?></td></tr>
<?php } ?>
</table><br>
<a href="input_data.php" style="text-decoration:none;"> KEMBALI INPUT DATA </a>
Download