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


if($_POST['nm'] != '')
{
    
 if(isset($_POST['id'])) 
 {
$id =addslashes($_POST['id']); 
$sir =addslashes($_POST['sir']);
$nm =addslashes($_POST['nm']);
$adm =addslashes($_POST['adm']);
$gen = $_POST['gen'];
$disa =addslashes($_POST['disa']);
$clas = addslashes($_POST['clas']);
$pt = addslashes($_POST['pt']);
$pn = addslashes($_POST['pn']);
$pc = addslashes($_POST['pc']);
$pe = addslashes($_POST['pe']);
$info=addslashes($_POST["info"]);
$bo=addslashes($_POST["bo"]);
$sta=addslashes($_POST["sta"]);
$cltype=addslashes($_POST["cltyp"]);

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

$sql=mysqli_query($con,"SELECT * FROM pupils where AdmNo='$adm' AND count !='$id'");
$num=mysqli_fetch_array($sql);
if($num>0)
{
  echo "Sorry! You can't assign two pupils same admission number"; 
}else
{
$sql=mysqli_query($con,"UPDATE pupils SET Locat='$cltype', Sirname='$sir',Boarder='$bo',Names='$nm',Claz='$clas',Gender='$gen',AdmNo='$adm',PType='$pt',PName='$pn',Disability='$disa',Contact='$pc',Email='$pe',Des='$info',Status='$sta' where count='$id'");
if($sql)
{
//$msgg='updated company profile details';
//$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 "Unable to update data";	
}	
}
 }else
  {  
$ctype =addslashes($_POST['cltype']);    
$sir =addslashes($_POST['sir']);
$nm =addslashes($_POST['nm']);
$adm =addslashes($_POST['adm']);
$gen = $_POST['gen'];
$disa =addslashes($_POST['disa']);
$clas = addslashes($_POST['clas']);
$pt = addslashes($_POST['pt']);
$pn = addslashes($_POST['pn']);
$pc = addslashes($_POST['pc']);
$pe = addslashes($_POST['pe']);
$info=addslashes($_POST["info"]);
$bo=addslashes($_POST["bo"]);

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

$sql=mysqli_query($con,"SELECT * FROM pupils where AdmNo='$adm'");
$num=mysqli_fetch_array($sql);
if($num>0)
{
  echo "Sorry! You can't assign two pupils same admission number"; 
}else
{
$sql=mysqli_query($con,"INSERT INTO pupils(Locat,Boarder,Sirname,Names,Claz,Gender,AdmNo,PType,PName,Disability,Contact,Email,RegDate,Des) values('$ctype','$bo','$sir','$nm','$clas','$gen','$adm','$pt','$pn','$disa','$pc','$pe','$timenow2','$info')");
if($sql)
{
//$msgg='updated company profile details';
//$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 "Unable to update data";	
}	
}
}
//echo $insert?'ok':'err';
} 
?>