Saturday, October 13, 2012

inserting data into database based by checkbox if checkbox selected.

<input type="button" name="Un_CheckAll" value="Uncheck All "
140onclick="UnCheckAll(document.myform.status)" />
141         
142        <th width="84" scope="row"><label>
143          <label>
144            <input type="submit" name="Simpan" id="Simpan" value="Simpan" />
145          </label>
146      </table>
147    <p>&nbsp;</p>
148    <p>&nbsp;</p>
149  </form>
150  <p>&nbsp;</p>
151  <p>&nbsp;</p>
152</blockquote>
153</body>
154 
155</html><?php
156if(isset($_POST['Simpan']))
157          {
158              
159               $status_id = $_POST['form1.status_id'];
160               $no_pend = $totalRows_kelas['no_pend'];
161               $nama_pelajar = $totalRows_kelas['nama_pelajar'];
162               $kelas = $totalRows_kelas['kelas'];
163               $kod_pensyarah = $totalRows_pensyarah['kod_pensyarah'];
164            if($status_id=1)
165              {
166             $sql="INSERT INTO pend_kursus( kod_pensyarah,kod_kursus, no_pend, kelas  )
167                        VALUES
168                        ('$kod_pensyarah','$kod_kursus','$no_pend' ,'$kelas' )";
169              }
170                 
171            echo "<script language='Javascript'>alert('Maklumat Telah Berjaya Disimpan');</script>";
172          }
173$result = mysql_query($sql);?>
174<?php
175mysql_free_result($pensyarah);
176?>
   <script LANGUAGE="Javascript">
002<!--
003 
004<!-- Begin
005function CheckAll(chk)
006{
007for (i = 0; i < chk.length; i++)
008chk[i].checked = true ;
009}
010 
011function UnCheckAll(chk)
012{
013for (i = 0; i < chk.length; i++)
014chk[i].checked = false ;
015}
016// End -->
017</script>
018 
019 
020<?php require_once('../Connections/connection.php'); ?>
021<?php
022 
023$kod_kursus=$_POST["kod_kursus"];  
024mysql_select_db($database_connection, $connection);
025$query_kursus = "SELECT * FROM m_kursus WHERE kod_kursus='$kod_kursus'";
026$kursus = mysql_query($query_kursus, $connection) or die(mysql_error());
027$row_kursus = mysql_fetch_assoc($kursus);
028$totalRows_kursus = mysql_num_rows($kursus);
029 
030$kelas=$_POST["kelas"];
031mysql_select_db($database_connection, $connection);
032$query_kelas = "SELECT * FROM m_pelajar WHERE kelas='$kelas'";
033$kelas = mysql_query($query_kelas, $connection) or die(mysql_error());
034$row_kelas = mysql_fetch_assoc($kelas);
035$totalRows_kelas = mysql_num_rows($kelas);
036 
037$kod_pensyarah=$_POST["kod_pensyarah"];
038mysql_select_db($database_connection, $connection);
039$query_pensyarah = "SELECT * FROM plogin WHERE kod_pensyarah = '$kod_pensyarah'";
040$pensyarah = mysql_query($query_pensyarah, $connection) or die(mysql_error());
041$row_pensyarah = mysql_fetch_assoc($pensyarah);
042$totalRows_pensyarah = mysql_num_rows($pensyarah);
043$result = mysql_query($query_kelas);
044 
045?>
046 
047<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
048<html xmlns="http://www.w3.org/1999/xhtml">
049<head>
050<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
051<title>Untitled Document</title>
052<style type="text/css">
053<!--
054body,td,th {
055    font-family: Verdana, Geneva, sans-serif;
056    font-weight: bold;
057    color: #FFF;
058    font-size: 14;
059}
060.tulisan {
061    font-family: "Arial Black", Gadget, sans-serif;
062}
063.tulisan {
064    font-family: "A Charming Font", "Felix Titling", "Floral Dawn", "Lucida Sans Unicode";
065}
066.tulisan {
067    font-family: Verdana, Geneva, sans-serif;
068}
069.tulisan {
070    font-size: 14px;
071}
072.tulisan {
073    font-family: "Kozuka Mincho Pro B", Utsaah, "Segoe UI";
074}
075.tulisan {
076    font-family: Verdana, Geneva, sans-serif;
077}
078.tulisan {
079    font-size: 16px;
080}
081#form table {
082    font-family: Verdana, Geneva, sans-serif;
083}
084-->
085</style></head>
086 
087<body background="image_e-kehadiran/Bs_Black_Floor_1440x900.jpg">
088<blockquote>
089  <table width="494" border="0" align="center">
090    <tr>
091      <th width="204" align="center" valign="middle" class="tulisan" scope="row"><blockquote>
092        <p class="tulisan"><span class="tulisan"> Kod Kursus :</span></p>
093      </blockquote></th>
094      <td width="232"><span class="tulisan"><?php echo $row_kursus['kod_kursus']; ?>&nbsp;</span></td>
095    </tr>
096    <tr>
097      <th align="center" class="tulisan" scope="row"><blockquote>
098        <p><span class="tulisan">Nama Kursus :</span></p>
099      </blockquote></th>
100      <td><span class="tulisan"><?php echo $row_kursus['nama_kursus']; ?>&nbsp;</span></td>
101    </tr>
102  </table>
103  <form id="form" name="myform" method="post" action="">
104    <p>&nbsp;</p>
105    <table width="733" height="63" border="1" align="center">
106      <tr>
107        <td width="220" height="29" align="center"><strong>No. Pendaftaran </strong></td>
108        <td width="231" align="center"><strong>Nama </strong></td>
109        <td width="174" align="center"><strong>Kelas </strong></td>
110        <td width="80" align="center"><strong>Daftar </strong></td>
111      </tr>
112      <?php
113      while($rows = mysql_fetch_array($result))
114{
115 
116 
117?>
118<?php
119     
120    ?>
121      <tr>
122        <td height="26" align="center" valign="middle"><label>
123          <?php  echo $no_pend ?>
124        </label>
125          &nbsp;</td>
126        <td align="center" valign="middle"><?php  echo $nama_pelajar ?>
127          &nbsp;</td>
128        <td align="center" valign="middle"><?php  echo $kelas ?>
129          &nbsp;</td>
130        <td align="center" valign="middle"><input name="status_id" type="checkbox" id="status" value="1" /></td>
131      </tr>
132      <?
133         
134}?>
135    </table>
136    <p>&nbsp;</p>
137    <table width="332" border="0" align="center">
138      <tr>
139        <th width="193" align="right" scope="row"><input type="button" name="Check_All" value="Check All"
140onclick="CheckAll(document.myform.status)" />
141          <input type="button" name="Un_CheckAll" value="Uncheck All "
142onclick="UnCheckAll(document.myform.status)" />
143         
144        <th width="84" scope="row"><label>
145          <label>
146            <input type="submit" name="Simpan" id="Simpan" value="Simpan" />
147          </label>
148      </table>
149    <p>&nbsp;</p>
150    <p>&nbsp;</p>
151  </form>
152  <p>&nbsp;</p>
153  <p>&nbsp;</p>
154</blockquote>
155</body>
156 
157</html><?php
158if(isset($_POST['Simpan']))
159          {
160              
161               $status_id = $_POST['form1.status_id'];
162               $no_pend = $totalRows_kelas['no_pend'];
163               $nama_pelajar = $totalRows_kelas['nama_pelajar'];
164               $kelas = $totalRows_kelas['kelas'];
165               $kod_pensyarah = $totalRows_pensyarah['kod_pensyarah'];
166            if($status_id=1)
167              {
168             $sql="INSERT INTO pend_kursus( kod_pensyarah,kod_kursus, no_pend, kelas  )
169                        VALUES
170                        ('$kod_pensyarah','$kod_kursus','$no_pend' ,'$kelas' )";
171              }
172                 
173            echo "<script language='Javascript'>alert('Maklumat Telah Berjaya Disimpan');</script>";
174          }
175$result = mysql_query($sql);?>
176<?php
177mysql_free_result($pensyarah);
178?>
179[attachment=22599:pend_kursus.php]
 

No comments:

Post a Comment