<?php
session_start();
include 'dbc.php';

$userid=$_SESSION["userid"];





$size = count($_POST['obt_mark']);

$i = 0;
while ($i < $size) {
	$obt_mark= $_POST['obt_mark'][$i];
	$id = $_POST['id'][$i];
	$result = mysql_query("SELECT * FROM admission WHERE id  = '$id' and user_id='$userid'");
$test = mysql_fetch_array($result);
if (!$result) 
		{
		die("Error: Data not found..");
		}
				$std_name=$test['std_name'] ;
				$rollno=$test['barcode'] ;
				$class_name=$test['class_name'] ;
				$bal=$test['bal'] ;
			
				
				
				$result1 = mysql_query("SELECT * FROM issueslip where user_id='$userid' order by id desc");
$test1 = mysql_fetch_array($result1);
if (!$result1) 
		{
		die("Error: Data not found..");
		}
				$month_name=$test1['monthname'] ;
				$od=$test1['id'] ;
				
				
				$result2 = mysql_query("SELECT * FROM issueslip where monthname='$month_name' and cname='$class_name'and rollno='$rollno'and stdname='$std_name' and user_id='$userid'");
$test2 = mysql_fetch_array($result2);
if (!$result2) 
		{
		die("Error: Data not found..");
		}
				
				$nettotal=$test2['nettotal'] ;
				

				
				 $admbal=$bal + $obt_mark;
				  $issuebal=$nettotal + $obt_mark;
				  
				  $sql2="update admission set bal='$admbal' where barcode='$rollno' and std_name='$std_name' and class_name='$class_name' and user_id='$userid';";
	mysql_query($sql2) or die("Error : " . mysql_error());
 	
	$query = "update issueslip set nettotal='$issuebal',fine='$obt_mark' where rollno='$rollno' and stdname='$std_name' and cname='$class_name' and monthname='$month_name' and user_id='$userid'";
mysql_query($query) or die ("Error in query: $query");
	
	++$i;

// do the update and print out some info just to provide some visual feedback



} 
echo "Record Update";

?>
<a href="fine.php"> Back </a>