oya bli ni kode yang udh aku cb bikin
form tambahsiswa.php
<?php
include '../konfigurasi/koneksi.php';
?>
<html>
<head>
<title>Belajar Bahasa Mandarin</title>
<style type="text/css" title="currentStyle">
@import "../css/grid_sytles.css";
@import "../css/themes/smoothness/jquery-ui-1.8.4.custom.css";
</style>
</head>
<body>
<div id="container">
<div class="ui-grid ui-widget ui-widget-content ui-corner-all">
<div class="ui-grid-header ui-widget-header ui-corner-top clearfix">
<div class="header">
<h2>
<center><span>Tambah Siswa</span></center>
</h2>
</div>
</div>
<form name="tambahsiswa" method="POST" action="proses_tambahsiswa.php" target="_self">
<table>
<tr>
<td width="150">NIS</td>
<td width="15">:</td>
<td><input type="text"name="NIS"size="30" maxlength="15">*)</td>
</tr>
<tr>
<td width="150">Nama Siswa</td>
<td width="15">:</td>
<td><input type="text"name="nama_siswa"size="30"maxlength="100">*)</td>
</tr>
<tr>
<td width="150">Password</td>
<td width="15">:</td>
<td colspan="4"><input type="password" name="password" size="30"maxlength="30">*)</td>
</tr>
<tr>
<td>Kelas</td>
<td>:</td>
<?php include '../admin/ajax1.php';
?>
</tr>
<tr>
<td width="150">ID Ujian </td>
<td width="15">:</td>
<td>
<div id="tampil">
</div>
</td>
</tr>
<tr>
<td width="150">Jenis Kelamin</td>
<td width="15">:</td>
<td><input type="radio" name="jenis_kelamin" value="Laki-laki">Laki-laki
<input type="radio"name="jenis_kelamin"value="Perempuan"> Perempuan *)
</td>
</tr>
<tr>
<td colspan="3"> *) isikan secara lengkap<br>
</td>
</tr>
<tr>
<th colspan='6'>
<input type=submit name=Simpan value=Submit>
<a href="javascript:history.go(-1)"><input type="button" value="Batal">
</a>
</th>
</tr>
</table>
</form>
<a href="datasiswa.php"></a>
</div>
</body>
ajax1.php
<script type="text/javascript">
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function kirim(id_subkelas)
{
var xmlHttp=GetXmlHttpObject()
var url="../admin/ajax2.php";
url1=url+"?id_subkelas="+id_subkelas;
xmlHttp.onreadystatechange=hasil;
function hasil()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("tampil").innerHTML=xmlHttp.responseText;
}
else
{
alert("Problem retrieving data:" + xmlhttp.statusText);
}
}
xmlHttp.open("GET",url1,true);
xmlHttp.send(null);
}
</script>
<td>
<select name="id_subkelas" OnChange="kirim(this.value)">
<option value='0'>- Pilih Nama Kelas -</option>
<?php
$query = mysql_query('SELECT * FROM subkelas ORDER BY nama_subkelas ASC');
while ($result = mysql_fetch_array($query)) {
echo "<option value='$result[id_subkelas]'>
$result[nama_subkelas]</option>";
}
?>
</select>
*)
</td>
ajax2.php
<?php
include "../konfigurasi/koneksi.php";
$id_subkelas = $_GET;
$sql = mysql_query("SELECT * FROM subkelas WHERE id_subkelas= '$id_subkelas'");
while ($data = mysql_fetch_array($sql)) {
echo"<option value='$data[id_ujian]'>$data[id_ujian]</option>";
}
?>
proses_tambahsiswa.php
<?php
session_start();
include '../konfigurasi/koneksi.php';
if (empty($_POST[NIS]) || empty($_POST[nama_siswa]) || empty($_POST[jenis_kelamin]) || empty($_POST[password])) {
echo"<script language='javascript'>alert('Isikan semua form yang bertanda bintang (*)');
window.location = '../admin/tambahsiswa.php'</script>";
} elseif ($_POST[id_subkelas] == '') {
echo "<script language='javascript'>alert('Isikan semua form yang bertanda bintang (*)');
window.location = '../admin/tambahsiswa.php'</script>";
} else {
$numRowsNIS = mysql_num_rows(mysql_query("SELECT NIS FROM siswa2 WHERE NIS = '$_POST[NIS]'"));
if ($numRowsNIS > 0) {
echo "<script language='javascript'>alert('NIS sudah digunakan,masukkan NIS yang benar.');
window.location = '../admin/tambahsiswa.php?module=manajemen_siswa&act=tambahsiswa'</script>";
} else {
echo"$_POST[NIS],$_POST[nama_siswa],$_POST[password],$_POST[id_subkelas],$_POST[id_ujian],$_POST[jenis_kelamin]";
mysql_query("insert into siswa2(NIS,nama_siswa,password,id_subkelas,id_ujian,jenis_kelamin)
values('$_POST[NIS]','$_POST[nama_siswa]','$_POST[password]','$_POST[id_subkelas]','$_POST[id_ujian]','$_POST[jenis_kelamin]')");
echo"<script language='javascript'>alert('Siswa $_POST[nama_siswa] dengan NIS = $_POST[NIS] berhasil ditambahkan/disimpan');
window.location='../admin/datasiswa.php'</script>";
}
}
?>
ni struktur tabel databasenya bli
/*Table structure for table `siswa2` */
CREATE TABLE `siswa2` (
`NIS` int(11) NOT NULL,
`nama_siswa` varchar(40) NOT NULL,
`password` varchar(15) NOT NULL,
`id_subkelas` varchar(25) NOT NULL,
`id_ujian` varchar(25) default '',
`jenis_kelamin` varchar(15) NOT NULL default '',
`tgl_ujian` date default NULL,
`nilai_ujian` int(11) default NULL,
PRIMARY KEY (`NIS`),
KEY `FK_siswa2_subkelas` (`id_subkelas`),
KEY `FK_siswa2_ujian` (`id_ujian`),
CONSTRAINT `FK_siswa2_subkelas` FOREIGN KEY (`id_subkelas`) REFERENCES `subkelas` (`id_subkelas`),
CONSTRAINT `FK_siswa2_ujian` FOREIGN KEY (`id_ujian`) REFERENCES `ujian` (`id_ujian`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Table structure for table `subkelas` */
CREATE TABLE `subkelas` (
`id_subkelas` varchar(15) NOT NULL,
`nama_subkelas` varchar(15) NOT NULL,
`jumlah_siswa` int(11) NOT NULL,
`id_kelas` int(11) NOT NULL,
`id_ujian` varchar(11) default NULL,
PRIMARY KEY (`id_subkelas`),
KEY `FK_subkelas` (`id_kelas`),
KEY `FK_subkelas_ujian` (`id_ujian`),
CONSTRAINT `FK_subkelas` FOREIGN KEY (`id_kelas`) REFERENCES `kelas` (`id_kelas`),
CONSTRAINT `FK_subkelas_ujian` FOREIGN KEY (`id_ujian`) REFERENCES `ujian` (`id_ujian`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;