Langkah - Langkah membuat Input Data dengan 2 Tabel menggunakan PHP MYSQL :
1. Buatlah Koneksi.php
<?php
$host='localhost';
$user='root';
$pass='';
$db='sekolah';
mysql_connect($host,$user,$pass) or die ("Tidak dapat terkoneksi " . mysql_error());
mysql_select_db($db) or die ("Database tidak ditemukan " . mysql_error());
?>
2. Buatlah formInputNilai.php
<?php
// koneksi database
include ("koneksi.php");
?>
<form name="form1" method="POST" action="simpan_Nilai.php">
<table width="400" border="0" align="center" cellpadding="1" cellspacing="1"
bordercolor="#00FF00" bgcolor="#33CC00">
<tr bgcolor="#CCFFCC">
<td height="50" colspan="2"><div align="center">INPUT DATA PENILAIAN SISWA </div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="40">Nis </td>
<td>:
<select name="nis">
<option>- Pilih Siswa -</option>
<?php
include "koneksi.php";
$nis=mysql_query("select * from siswa");
while ($baca=mysql_fetch_array($nis))
{
echo"<option value='".$baca['nis']."'>".$baca['nis']."-".$baca['nm_siswa']."</option>";
}
?>
</select></td>
</tr>
</tr>
<tr bgcolor="#FFFFFF">
<td height="40">Kode Mapel </td>
<td>:
<select name="kd_mapel">
<option>- Pilih Mata Pelajaran -</option>
<?php
include "koneksi.php";
$kd_mapel=mysql_query("select * from mapel");
while ($baca=mysql_fetch_array($kd_mapel))
{
echo"<option value='".$baca['kd_mapel']."'>".$baca['kd_mapel']."-".$baca['nm_mapel']."</option>";
}
?>
</select></td>
</tr>
</tr>
<tr bgcolor="#FFFFFF">
<td height="40">Nilai </td>
<td>:
<input name="nilai" type="text" id="nilai"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td> </td>
<td height="50"><input type="submit" name="Submit" value="Simpan"></td>
</tr>
</table>
</form>
3. Buatlah Simpan_Nilai.php
<?php
include ("koneksi.php");
$id=$_POST['id'];
$nis=$_POST['nis'];
$kd_mapel=$_POST['kd_mapel'];
$nilai=$_POST['nilai'];
$simpan="insert into nilai values('$id','$nis','$kd_mapel',$nilai)";
mysql_query($simpan);
echo "data berhasil disimpan ";
include ("tampil_nilai.php");
echo "<br>";
echo "Back : <a href=formInputNilai.php>back</a>";
?>
4. Buatlah Tampil Data Nilai menggunakan Tabel View
<html>
<head><title>Daftar Nilai Siswa</title></head>
<body>
<center>DAFTAR NILAI SISWA</center><br><br>
<table width="900" border="0" align="center" cellpadding="2"
cellspacing="1" bgcolor="#000000" celpading="2" celspacing="1" >
<tr bgcolor="#CCFFFF">
<td><div align="center"><strong>No</strong></div></td>
<td><div align="center"><strong>id</strong></div></td>
<td><div align="center"><strong>Nis</strong></div></td>
<td><div align="center"><strong>Nama Siswa</strong></div></td>
<td><div align="center"><strong>Kode Mapel</strong></div></td>
<td><div align="center"><strong>Nama Mapel</strong></div></td>
<td><div align="center"><strong>Nilai</strong></div></td>
</tr>
<?php
// koneksi database
include ("koneksi.php");
// membaca tabel dan menampilkannya
$no = 0;
$tampil="select * from V_Nilai";
$qryTampil=mysql_query($tampil);
while ($dataTampil=mysql_fetch_array($qryTampil)) {
$no++;
?>
<tr bgcolor="#FFFFFF">
<td><?php echo $no ; ?></td>
<td><?php echo $dataTampil['ID']; ?></td>
<td><?php echo $dataTampil['NIS']; ?></td>
<td><?php echo $dataTampil['NAMA_SISWA']; ?></td>
<td><?php echo $dataTampil['KODE_MAPEL']; ?></td>
<td><?php echo $dataTampil['NAMA_MAPEL']; ?></td>
<td><?php echo $dataTampil['NILAI']; ?></td>
</tr>
<?php } ?>
</table>
Hasil :
Komentar ini telah dihapus oleh pengarang.
BalasHapus