gimana caranya agar saya bisa menyimpan data dengan chekbox...
ceritanya begini,, sya buat absensi siswa, proses absennya perkelas dan untuk keterangan kehadiranya di pilih dengan chekbox atau cheklis,,, yang saya mau tanya gimana caranya menyimpan data yang di ceklis tersebut ke dalam database? terima kasih sebelumnya...
ini kode absensi.php
<?php
session_start();
if (isset($_SESSION['level']) && isset($_SESSION['username']))
{
if ($_SESSION['level'] == "admin")
{
?>
<!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>Administrator dan User Area</title>
</head>
<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="83%">
<tr>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
<td valign="bottom" background="../gambar/bg_left.gif"><img src="../gambar/bg_left.gif" alt="" width="17" height="16" border="0"></td>
<td bgcolor="#FFFFFF"><table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><?php include "header.php"; ?></td>
</tr>
<tr>
<td background="../gambar/fon02.gif" height="34"><div align="center"></div></td>
</tr>
</table>
<p align="center" class="px">
<?php include "menu.php"; ?>
<table width="671" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td width="549"><table width="598" border="0" align="center">
<tr>
<td width="518"><div align="center">
<h2><strong>INPUT NILAI SISWA</strong></h2>
<div align="center"><a href="nilai_siswa.php">Laporan Nilai</a> </div></td>
</div></td>
<div class="post">
<div class="entry">
<table width="500" border="1" align="center" cellpadding="1" cellspacing="0">
<tr bgcolor="#FFFF99">
<th>No</th><th>Nama Kelas</th><th>Jumlah Siswa</th><th>Aksi</th>
</tr>
<?php
include "conn.php";
$kelas=mysql_query("select * from kelas order by kelas asc",$koneksi);
//untuk mencari jumlah
echo "Jumlah Kelas : ".$jumlah_kelas=mysql_num_rows($kelas);
echo " >> Jumlah Siswa : ".$jumlah_siswa=mysql_num_rows(mysql_query("select * from tblsiswa",$koneksi));
echo "<br><br>";
while($row=mysql_fetch_array($kelas)){
//mencari jumlah siswa di masing-masing kelas
$siswa=mysql_query("select * from tblsiswa where kelas='$row[kelas]'",$koneksi);
$jumlah=mysql_num_rows($siswa);
?>
<tr>
<td align="center"><?php echo $c=$c+1; ?></td><td align="center"><?php echo $row['kelas']; ?></td><td align="center"><?php echo $jumlah;?> Orang</td>
<td align="center"><a href="input_absensi.php?kelas=<?php echo $row['kelas'];?>">Absensi</a></td>
</tr>
<?php
}
?>
</table>
</p>
</div>
</tr>
</table>
<div class="px" align="center"><img src="../gambar/bot01.jpg" width="780" height="9" alt="" border="0"></div>
<table border="0" cellspacing="0" cellpadding="0" width="780" align="center">
<tr>
<td><p align="center">
<?php include "footer.php"; ?>
</p></td>
<td height="50">
<p class="bot"> </p>
</td>
</tr>
</table>
</td>
<td valign="bottom" background="../gambar/bg_right.gif"><img src="../gambar/bg_right.gif" alt="" width="17" height="16" border="0"></td>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>
</body>
</html>
<?
}
else
{
// jika levelnya bukan admin, tampilkan pesan
echo "<script type='text/javascript'>
{
if(alert('Sorry gank!! Anda tidak berhak mengakses halaman ini karena bukan admin.')){document.location='login.php';}
}
</script>";
}
}
else
{
echo "<script type='text/javascript'>
{
if(alert('Login Dulu dong Frend!!')){document.location='login.php';}
}
</script>";
}
?>
ini kode input_absensi.php
<?php
session_start();
if (isset($_SESSION) && isset($_SESSION))
{
if ($_SESSION == "admin")
{
include "conn.php";
$kelas=$_GET;
$query=mysql_fetch_array(mysql_query("select * from kelas where kelas='$kelas'"));
?>
<!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>Administrator dan User Area</title>
</head>
<body leftmargin=0 topmargin=0 marginheight="0" marginwidth="0" bgcolor="#ffffff">
<table border="0" cellspacing="0" cellpadding="0" width="100%" height="83%">
<tr>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
<td valign="bottom" background="../gambar/bg_left.gif"><img src="../gambar/bg_left.gif" alt="" width="17" height="16" border="0"></td>
<td bgcolor="#FFFFFF"><table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><?php include "header.php"; ?></td>
</tr>
<tr>
<td background="../gambar/fon02.gif" height="34"><div align="center"></div></td>
</tr>
</table>
<p align="center" class="px">
<?php include "menu.php"; ?>
<table width="671" border="0" align="center" cellpadding="1" cellspacing="0">
</p>
<p align="center"> </p>
</td>
<td width="515"><table width="510" border="0" align="center">
<tr>
<td valign="top"><h2 align="center"><strong>Nilai Siswa SMA Negeri 1 Bukit </strong></h2>
<div class="post">
<h2 class="title"><a href="#">ABSENSI KELAS <?php echo $query;?></a></h2>
<div class="entry">
<p>
<form action="?page=proses" method="post" name="postform">
<input type="hidden" value="<?php echo $query;?>" name="kelas"/>
<table class="datatable">
<tr>
<td width="24%" align="left" colspan="6">Tanggal : <input type="text" name="tanggal" value="<?php if(empty($_POST)){ echo $tanggal;}else{ echo "$_POST[tgl]$_GET[tgl]"; }?>" size="11"><a href="javascript:void(0)" onClick="if(self.gfPop)gfPop.fPopCalendar(document.postform.tanggal);return false;" ><img name="popcal" align="absmiddle" src="calender/calbtn.gif" width="34" height="29" border="0" alt=""></a></td>
</tr>
<table width="644" border="1" align="center" cellpadding="1" cellspacing="0">
<tr bgcolor="#FFFF99">
<td width="30"><div align="center"><strong>No</strong></div></td>
<td width="181"><div align="center"><strong>Nama Siswa</strong></div></td>
<td width="74"><div align="center"><strong>Hadir</strong></div></td>
<td width="50"><div align="center"><strong>Sakit</strong></div></td>
<td width="70"><div align="center"><strong>Ijin</strong></div></td>
<td width="68"><div align="center"><strong>Alfa</strong></div></td>
</tr>
<?php
//penting buat kasih nilai awal cekbox
$no=0;
$query=mysql_query("select * from tblsiswa where kelas='$kelas'");
while($row=mysql_fetch_array($query)){
?>
<tr>
<td><?php echo $c=$c+1;?></td><td><?php echo $row;?></td>
<td align="center">
<?php
echo "<input type=checkbox name=hadir[] value=$row[nis] id='$no'>";
$no++;
?>
</td>
<td align="center">
<?php
echo "<input type=checkbox name=sakit[] value=$row[nis] id=$no>";
$no++;
?>
</td>
<td align="center">
<?php
echo "<input type=checkbox name=ijin[] value=$row[nis] id=$no>";
$no++;
?>
</td>
<td align="center">
<?php
echo "<input type=checkbox name=alfa[] value=$row[nis] id=$no>";
$no++;
?>
</td>
</tr>
<?php
}
echo "
<tr>
<td></td>
<td></td>
<td align=center>
<input type='button' name='pilih' onclick='for (i=0;i<$no;i++){document.getElementById(i).checked=true;}' value='Check All'>
</td>
<td align=center>
<input type='button' name='pilih' onclick='for (i=0;i<$no;i++){document.getElementById(i).checked=false;}' value='Uncheck All'>
</td>
<td></td>
<td></td>
</tr>";
?>
</table>
<br />
<input type="checkbox" name="selesai" value="yes" />Tandai Kelas Selesai
<br /><br />
<input type="submit" value="Submit" /> <a href="absensi.php">Kembali</a>
</form>
</p>
</div>
</div>
<iframe width=174 height=189 name="gToday:normal:calender/agenda.js" id="gToday:normal:calender/agenda.js" src="calender/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;">
</iframe>
</table>
<p> </p>
<div class="px" align="center"><img src="../gambar/bot01.jpg" width="780" height="9" alt="" border="0"></div>
<table border="0" cellspacing="0" cellpadding="0" width="780" align="center">
<tr>
<td><p align="center">
<?php include "footer.php"; ?>
</p></td>
<td height="50">
<p class="bot"> </p>
</td>
</tr>
</table><tr></table>
</td>
<td valign="bottom" background="../gambar/bg_right.gif"><img src="../gambar/bg_right.gif" alt="" width="17" height="16" border="0"></td>
<td width="50%" background="../gambar/bg.gif"><img src="../gambar/px1.gif" width="1" height="1" alt="" border="0"></td>
</tr>
</table>
</body>
</html>
<?php
}
else
{
// jika levelnya bukan admin, tampilkan pesan
echo "<script type='text/javascript'>
{
if(alert('Sorry gank!! Anda tidak berhak mengakses halaman ini karena bukan admin.')){document.location='login.php';}
}
</script>";
}
}
else
{
echo "<script type='text/javascript'>
{
if(alert('Login Dulu dong Frend!!')){document.location='login.php';}
}
</script>";
}
?>
ini kode proses.php
<?php
include "conn.php";
$kelas=$_POST;
$tanggal=$_POST;
if(isset($_POST)){
if(!empty($_POST)){
//parameter
$nis=$_POST;
$jumlah=count($nis);
for($i=0;$i<$jumlah;$i++){
$hadir=mysql_query("insert into absensi(nis,kelas,keterangan,tanggal,selesai) values('$nis[$i]','$kelas','h','$tanggal','yes')",$koneksi);
}
?>
<script language="javascript">document.location.href="?page=view_absensi&kelas=<?php echo $kelas;?>&tanggal=<?php echo $tanggal;?>";</script>
<?php
}
if(!empty($_POST)){
//parameter
$nis=$_POST;
$jumlah=count($nis);
for($i=0;$i<$jumlah;$i++){
$hadir=mysql_query("insert into absensi(nis,kelas,keterangan,tanggal,selesai) values('$nis[$i]','$kelas','s','$tanggal','yes')",$koneksi);
}
?>
<script language="javascript">document.location.href="?page=view_absensi&kelas=<?php echo $kelas;?>&tanggal=<?php echo $tanggal;?>";</script>
<?php
}
if(!empty($_POST)){
//parameter
$nis=$_POST;
$jumlah=count($nis);
for($i=0;$i<$jumlah;$i++){
$hadir=mysql_query("insert into absensi(nis,kelas,keterangan,tanggal,selesai) values('$nis[$i]','$kelas','i','$tanggal','yes')",$koneksi);
}
?>
<script language="javascript">document.location.href="?page=view_absensi&kelas=<?php echo $kelas;?>&tanggal=<?php echo $tanggal;?>";</script>
<?php
}
if(!empty($_POST)){
//parameter
$nis=$_POST;
$jumlah=count($nis);
for($i=0;$i<$jumlah;$i++){
$hadir=mysql_query("insert into absensi(nis,kelas,keterangan,tanggal,selesai) values('$nis[$i]','$kelas','a','$tanggal','yes')",$koneksi);
}
?>
<script language="javascript">document.location.href="?page=view_absensi&kelas=<?php echo $kelas;?>&tanggal=<?php echo $tanggal;?>";</script>
<?php
}
}else{
unset($_POST);
?><script language="javascript">document.location.href="?page=input_absensi&kelas=<?php echo $kelas;?>&tanggal=<?php echo $tanggal;?>";</script><?php
}
?>