<?php
include "connect.php";
//)){

$nim= $_COOKIE['nim'];
$namamhs=$_COOKIE['namamhs'];
$tingkat=$_COOKIE['tingkat'];
$kelas=$_COOKIE['kelas'];
$semester= $_COOKIE['semester'];
$ta = $_COOKIE['ta'];
$cek = mysql_query("select * from krs where nim='$nim' AND semester='$semester'AND ta='$ta'");
$hasil=mysql_num_rows($cek);
if($hasil>0)
{
die("sudah pernah input");
}
echo"<table>";
foreach($_POST['kd_mtk'] as $valkode){
 mysql_query("insert into krs (nim,kd_mtk,semester,ta) values ('$nim','$valkode','$semester','$ta')");
}
echo "<tr><td>NIM</td><td>: $nim</td></tr>
      <tr><td>Nama</td><td>: $namamhs</td></tr>
	  <tr><td>Tingkat</td><td>: $tingkat $kelas</td></tr>
	  <tr><td>Semester</td><td>: $semester</td></tr>
	  <tr><td>TA</td><td>: $ta </td></tr>";
	  //'</table>';
?>
<table width="753" height="29" border="1">
<tr><th width="39" height="23">No.</th>
 <th width="122">Kode</th>
 <th width="480">Matakuliah</th>
 <th width="84">SKS</th>
</tr>
<?php
include "connect.php";
$sqlkrs = mysql_query("SELECT * FROM krs, mtk WHERE nim='$nim'
 AND krs.kd_mtk = mtk.kd_mtk
 AND krs.semester='$semester' AND krs.ta='$ta'");
$jumsks = 0;
$i = 1;
while($datakrs = mysql_fetch_array($sqlkrs)){
 echo "<tr align=center><td>$i</td>";
 echo "<td>$datakrs[kd_mtk]</td>";
 echo "<td align=left>$datakrs[nm_mtk]</td>";
 echo "<td>$datakrs[sks]</td></tr>";
 $jumsks = $jumsks + $datakrs['sks'];
 $i++;
}
echo "<tr align=center><td colspan=3>JUMLAH</td><td>$jumsks</td></tr>";
?>
</table>

