<?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['id']))
{
$id=addslashes($_POST['id']);
$grd=addslashes($_POST['grd']);
$exa=addslashes($_POST['exa']);

if($grd=='GRADE 1' || $grd=='GRADE 2' || $grd=='GRADE 3')
{
$query=mysqli_query($con,"select * from CBC1 where PID='$id' AND  Grad='$grd' AND EID='$exa'");
$num=mysqli_fetch_array($query);
if($num>0)
{
echo "Learner exist in selected exam data";
}else
{
$sql=mysqli_query($con,"INSERT INTO CBC1(EID,PID,Grad)values('$exa','$id','$grd')");
if($sql)
{
$msg='added learners exam 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
{
 $query=mysqli_query($con,"select * from CBC2 where PID='$id' AND  Grad='$grd' AND EID='$exa'");
$num=mysqli_fetch_array($query);
if($num>0)
{
echo "Learner exist in selected exam data";
}else
{
$sql=mysqli_query($con,"INSERT INTO CBC2(EID,PID,Grad)values('$exa','$id','$grd')");
if($sql)
{
$msg='added learners exam 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';
}  
}   
}
}
?>