<?php
$date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
$timenow=$date->format('Y-m-d H:i:s');
$timenow2=$date->format('Y-m-d');
$month=$date->format('M');
session_start();
include('../include/config.php');
$iduser= $_SESSION['user_idd'];
$yr='';
$trm='';
$pid='';
$pname='';

if(isset($_POST['id'])) 
 {
$id =$_POST['id']; 
$tu =$_POST['tu'];
$bo =$_POST['bo'];
$tr =$_POST['tr'];
$un = $_POST['un'];
$mo =$_POST['mo'];
$pe = $_POST['pe'];
$di = $_POST['di'];
$bk = $_POST['bk'];
$tot = $_POST['tot'];
$adm = $_POST['adm'];
$tab = $_POST['tab'];
$dev = $_POST['dev'];
$assbk = $_POST['asbk'];

$sql = "SELECT * FROM Fees2 where id='$id'";
$result = $con->query($sql);
while($row = $result->fetch_assoc()) 
{
$yr=$row['Year'];
$trm=$row['Term'];
$pid=$row['pid'];
}

$sqlpupil = "SELECT * FROM pupils where count='$pid'";
$result = $con->query($sqlpupil);
while($row = $result->fetch_assoc()) 
{
$pname=$row['Names'];
}

$sql=mysqli_query($con,"UPDATE Fees2 SET TutionF='$tu',Assbok='$assbk',DiariesF='$di',BoF='$bo',TranF='$tr',UniF='$un',MotF='$mo',PEF='$pe',TxtF='$bk',Dev='$dev',AdmF='$adm',Tablet='$tab' WHERE  id='$id'");
if($sql)
{
$msgg='updated fee data for '.$pname.' for '.$trm.' '.$yr;
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msgg','$timenow','$timenow2','update','$month')");
// if($sql3)
// { }
echo "Fee successfully saved";
}else
{
echo "Unable to update data";	
}	
}
?>