<?php 
session_start();
//mysql_connect("localhost","root","vertrigo") or die("Error Connecting Server");
//mysql_select_db("sm") or die("Error Opening Database");
include 'dbc.php';

$id =$_REQUEST['id'];
$userid=$_SESSION['userid'];
$result = mysql_query("SELECT * FROM issueslip WHERE id  = '$id' and user_id='$userid'");
$test = mysql_fetch_array($result);
if (!$result) 
		{
		die("Error: Data not found..");
		}
				
				$class_name=$test['cname'] ;
			$std_name=$test['stdname'] ;
$std_rollno=$test['rollno'] ;
$amount=$test['nettotal'] ;
	  
	   $sql = "select * from admission where class_name='$class_name' and std_rollno='$std_rollno' and user_id='$userid'";
   $std_ledger=mysql_query($sql) or die("Error : " . mysql_error());
   $app=mysql_fetch_array($std_ledger);
   $bal=$app["bal"];
   
  $tbal=$bal - $amount ;
	  $sql2="update admission set bal='$tbal' where std_rollno='$std_rollno' and class_name='$class_name' and user_id='$userid';";
	mysql_query($sql2) or die("Error : " . mysql_error());

$sql4 = "delete from issueslip where id='$id' and user_id='$userid'";
mysql_query($sql4) or die("Error : " . mysql_error());



$Message = "Record Deleted";
    header("Location:campuswise_receivable_no.php?Message={$Message}");
/*$sql="Select * from agents where userid='$user_id'";
$data=mysql_query($sql) or die ("Error:" . mysql_error());
$userdata=mysql_fetch_array($data);
$email=$userdata["e_mail"];
mail($email . ",info@lalburj.com","Candidate Information","Candidate Data Posted Successfully","Passport No:" . $app_pp_no . " of " . $app_name . "Has been Posted Successfully By:" . $_SESSION["userid"]);*/
?>
