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

$em='';

if(isset($_POST['la']))
{
$la=addslashes($_POST['la']);
$co=addslashes($_POST['co']);
$lug=addslashes($_POST['lug']);
$insh=addslashes($_POST['insh']);
$ma=addslashes($_POST['ma']);
$sci=addslashes($_POST['sci']);
$soci=addslashes($_POST['soci']);
$cr=addslashes($_POST['cr']);
$tot=addslashes($_POST['total']);

$query=mysqli_query($con,"select * from Marks");
$num=mysqli_fetch_array($query);
if($num>0)
{

$sql=mysqli_query($con,"UPDATE Marks SET Lang='$la',Comp='$co',Lugha='$lug',Insha='$insh',Maths='$ma',Scie='$sci',SS='$soci',CRE='$cr',SSCRE='$tot'");
if($sql)
{
$msg='updated marks data';
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msg','$timenow','$timenow2','save','$month')");

echo "Successfully saved";
}else
{
echo 'Unable to save';
}

}else
{
$sql=mysqli_query($con,"INSERT INTO Marks(Lang,Comp,Lugha,Insha,Maths,Scie,SS,CRE,SSCRE) values('$la','$co','$lug','$insh','$ma','$sci','$soci','$cr','$tot')");
if($sql)
{
$msg='saved marks data';
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msg','$timenow','$timenow2','save','$month')");

echo "Successfully saved";
}else
{
echo 'Unable to save';
}  

}
}
?>