<?php
include('../include/config.php');
//error_reporting(0);
session_start();
$iduser= $_SESSION['user_idd'];

$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');

if(isset($_POST['sid']))
 {
$sid = addslashes($_POST['sid']);
$amt=addslashes($_POST["amt"]);
$trm=addslashes($_POST["trm"]);
$grd=addslashes($_POST["grd"]);
$yr=addslashes($_POST["yr"]);

$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');

$query=mysqli_query($con,"SELECT * FROM Balances WHERE Year='$yr' AND Term='$trm' AND SID='$sid'");
$num=mysqli_fetch_array($query);
if($num>0)
{
$sql=mysqli_query($con,"UPDATE Balances SET `SID`='$sid', `Term`='$trm', `Year`='$yr', `Grad`='$grd', `Amount`='$amt' WHERE Year='$yr' AND Term='$trm' AND SID='$sid'");
if($sql)
{
 echo 'success';
}else
{
echo "Unable to save data";	
}    
    
}else
{
$sql=mysqli_query($con,"INSERT INTO Balances( `SID`, `Term`, `Year`, `Grad`, `Amount`) values('$sid','$trm','$yr','$grd','$amt')");
if($sql)
{
 echo 'success';
}else
{
echo "Unable to save data";	
}
}
 }
 ?>