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

$sscr=addslashes($_POST['sscr']);
$tm=addslashes($_POST['tm']);

//$tot=addslashes($_POST['total']);
$pid=addslashes($_POST['pid']);
$eid=$_POST['eid'];


$query=mysqli_query($con,"select * from MarksScore where EID='$eid' AND PID='$pid'");
$num=mysqli_fetch_array($query);
if($num>0)
{
 
$sqll=mysqli_query($con,"UPDATE MarksScore SET Lang='$la',Comp='$co',Lugha='$lug',Insha='$insh',Maths='$ma',Scie='$sci',SS='$soci',Grade='$grd',CRE='$cr',Remark='$rem',SSCRE='$sscr',Total='$tm' WHERE PID='$pid' AND EID='$eid'");

if($sqll)
{
$msg=addslashes("updated pupil's marks");
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msg','$timenow','$timenow2','save','$month')");

echo "Details saved successfully";
}else
{
echo 'Unable to save';
} 

 
}else
{
//$sql=mysqli_query($con,"INSERT INTO Scores(Pid,Eid,Lang,Comp,Lugha,Insha,Maths,Scie,SS,CRE) values('$pid','$eid','$la','$co','$lug','$insh','$ma','$sci','$soci','$cr')");
$sqll=mysqli_query($con,"INSERT INTO MarksScore(PID,EID,Lang,Comp,Lugha,Insha,Maths,Scie,SS,CRE,Remark,Grade,SSCRE,Total) values('$pid','$eid','$la','$co','$lug','$insh','$ma','$sci','$soci','$cr','$rem','$grd','$sscr','$tm')");

if($sqll)
{
$msg=addslashes("added pupil's marks");
$sql3=mysqli_query($con,"INSERT INTO activity(user,Action,Tim,Dat,shortmsg,Month)values('$iduser','$msg','$timenow','$timenow2','save','$month')");

echo "Details saved successfully";
}else
{
echo 'Unable to save';
}  
}
}
?>