<?php 
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');
//$finaldate='Today: '.$date->format('l d M Y - H:i:s');

 include('../include/config.php');
 
 if(isset($_POST["pe"]))
 {
 $pe=addslashes($_POST["pe"]);
 $item=addslashes($_POST["item"]);
 $id=addslashes($_POST["id"]);
 $bgt=addslashes($_POST["bgt"]);

$sql=mysqli_query($con,"SELECT * FROM Incomebudget where Period='$pe' AND ID ='$id'");
$num=mysqli_fetch_array($sql);
if($num>0)
{
 $sql=mysqli_query($con,"UPDATE  Incomebudget SET Item='$item',Amount='$bgt' where Period='$pe' AND ID='$id'");
if($sql)
{
 $msgg='updated budget Amount for '.$item.' for the period '.$pe;
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msgg','$timenow','$timenow2','update','$month')");
if($sql3)
{ } 
echo 'success';
}
  
}else
{
$sql=mysqli_query($con,"INSERT INTO Incomebudget(Item,Period,ID,Amount,EntryDate) values ('$item','$pe','$id','$bgt','$timenow2')");
if($sql)
{
$msgg='added budget Amount for '.$item.' for the period '.$pe;
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msgg','$timenow','$timenow2','update','$month')");
if($sql3)
{ } 
echo "success";
}else
{
echo "Error in saving data";
}
}
 }
?>