<?php

include '../db_connect.php';
 foreach($_POST as $key => $value){
$_POST[$key] = mysqli_real_escape_string($con,trim($value));
}
if($_GET['mode']=="update")
{
if(mysqli_query($con,"UPDATE `empinfo` SET `CMP` = '$_POST[CMP]', `ECode` = '$_POST[ECode]',`password` = '$_POST[password]', `EName` = '$_POST[EName]', `EAddress` = '$_POST[EAddress]', `EBdate` = STR_TO_DATE('$_POST[EBdate]','%d/%m/%Y'), `EAge` = '$_POST[EAge]', `EDEmployed` = '$_POST[EDEmployed]', `Designation` = '$_POST[Designation]', `Department` = '$_POST[Department]', `Status` = '$_POST[Status]', `EGender` = '$_POST[EGender]', `ECivilStatus` = '$_POST[ECivilStatus]', `ContactNumber` = '$_POST[ContactNumber]', `reptime` = '$_POST[reptime]', `closetime` = '$_POST[closetime]', `salary` = '$_POST[salary]', `holidays` = '$_POST[holidays]', `other1` = '$_POST[other1]', `other2` = '$_POST[other2]', `HRA` = '$_POST[HRA]', `Conveyance` = '$_POST[Conveyance]', `Medical` = '$_POST[Medical]', `Bonus` = '$_POST[Bonus]', `basicsalary` = '$_POST[basicsalary]', `otallowance` = '$_POST[otallowance]', `daallowance` = '$_POST[daallowance]', `cpf` = '$_POST[cpf]', `clic` = '$_POST[clic]', `epf` = '$_POST[epf]', `elic` = '$_POST[elic]', `pTax` = '$_POST[pTax]', `passport` = '$_POST[passport]', `passexp` = STR_TO_DATE('$_POST[passexp]','%d/%m/%Y'), `issuedin` = '$_POST[issuedin]', `license` = '$_POST[license]', `licenseexp` = STR_TO_DATE('$_POST[licenseexp]','%d/%m/%Y'), `licencestype` = '$_POST[licencestype]', `visano` = '$_POST[visano]', `visanoexp` = STR_TO_DATE('$_POST[visanoexp]','%d/%m/%Y'), `visatype` = '$_POST[visatype]', `idno` = '$_POST[idno]', `idnoexp` = STR_TO_DATE('$_POST[idnoexp]','%d/%m/%Y'), `dateofjoin` = STR_TO_DATE('$_POST[dateofjoin]','%d/%m/%Y'), `PETROCARD` = '$_POST[PETROCARD]', `pcform` = '$_POST[pcform]', `petexp` = STR_TO_DATE('$_POST[petexp]','%d/%m/%Y'), `ContactNumber2` = '$_POST[ContactNumber2]', `Peraddress` = '$_POST[Peraddress]', `cname` = '$_POST[cname]', `relation` = '$_POST[relation]', `child` = '$_POST[child]', `mobile` = '$_POST[mobile]', `hometele` = '$_POST[hometele]', `nfamily` = '$_POST[nfamily]', `sname` = '$_POST[sname]', `scountry` = '$_POST[scountry]', `syear` = '$_POST[syear]', `scompleted` = '$_POST[scompleted]', `sgrade` = '$_POST[sgrade]', `Dname` = '$_POST[Dname]', `Dcountry` = '$_POST[Dcountry]', `Dyear` = '$_POST[Dyear]', `Dcompleted` = '$_POST[Dcompleted]', `Dgrade` = '$_POST[Dgrade]', `Gname` = '$_POST[Gname]', `Gcountry` = '$_POST[Gcountry]', `Gyear` = '$_POST[Gyear]', `Gcomleted` = '$_POST[Gcomleted]', `Ggrade` = '$_POST[Ggrade]', `oname` = '$_POST[oname]',`oyear` = '$_POST[oyear]', `ocountry` = '$_POST[ocountry]', `ocompleted` = '$_POST[ocompleted]', `ograde` = '$_POST[ograde]' WHERE `empinfo`.`EntryID` = '$_POST[EntryID]'"))
//echo "$_POST[compid]###$_POST[name]###$_POST[address]###$_POST[city]###$_POST[incstax]###$_POST[telephone]###Record Updated Susscessfully!!!";
echo "Record Updated Susscessfully!!!";

else
echo "Error:".mysqli_error($con);
}


else if($_GET['mode']=="insert")
{
$qry=mysqli_query($con,"select EntryID from empinfo where ECode='$_POST[ECode]'");
if(mysqli_num_rows($qry)>0)
die('Error :Employee Code Already Exits!!');	
	
if(mysqli_query($con,"INSERT INTO `empinfo` (`EntryID`, `CMP`, `ECode`,`password`, `EName`, `EAddress`, `EBdate`, `EAge`, `EDEmployed`, `Designation`, `Department`, `Status`, `EGender`, `ECivilStatus`, `ContactNumber`, `reptime`, `closetime`, `salary`, `holidays`, `other1`, `other2`, `HRA`, `Conveyance`, `Medical`, `Bonus`, `basicsalary`, `otallowance`, `daallowance`, `cpf`, `clic`, `epf`, `elic`, `pTax`, `passport` , `passexp` , `issuedin` , `license` , `licenseexp` , `licencestype`, `visano` , `visanoexp` , `visatype` , `idno` , `idnoexp`, `dateofjoin`, `PETROCARD`,`pcform`, `petexp`,`ContactNumber2`,`Peraddress`, `cname`, `relation`, `child`, `mobile`, `hometele`, `nfamily`, `sname`, `scountry`, `syear`, `scompleted`, `sgrade`, `Dname`, `Dcountry`, `Dyear`, `Dcompleted`, `Dgrade`, `Gname`, `Gcountry`,`Gcomleted`,`Gyear`, `Ggrade`, `oname`, `ocountry`, `oyear`, `ocompleted`, `ograde` ) VALUES (NULL, '$_POST[CMP]', '$_POST[ECode]','$_POST[password]', '$_POST[EName]', '$_POST[EAddress]', STR_TO_DATE('$_POST[EBdate]','%d/%m/%Y'), '$_POST[EAge]', '$_POST[EDEmployed]', '$_POST[Designation]', '$_POST[Department]', '$_POST[Status]', '$_POST[EGender]', '$_POST[ECivilStatus]', '$_POST[ContactNumber]', '$_POST[reptime]', '$_POST[closetime]', '$_POST[salary]', '$_POST[holidays]', '$_POST[other1]', '$_POST[other2]', '$_POST[HRA]', '$_POST[Conveyance]', '$_POST[Medical]', '$_POST[Bonus]', '$_POST[basicsalary]', '$_POST[otallowance]', '$_POST[daallowance]', '$_POST[cpf]', '$_POST[clic]', '$_POST[epf]', '$_POST[elic]', '$_POST[pTax]', '$_POST[passport]', STR_TO_DATE('$_POST[passexp]','%d/%m/%Y'), '$_POST[issuedin]', '$_POST[license]',   STR_TO_DATE('$_POST[licenseexp]','%d/%m/%Y'),  '$_POST[licencestype]',  '$_POST[visano]',  STR_TO_DATE('$_POST[visanoexp]','%d/%m/%Y'),  '$_POST[visatype]', '$_POST[idno]', STR_TO_DATE('$_POST[idnoexp]','%d/%m/%Y'),  STR_TO_DATE('$_POST[dateofjoin]','%d/%m/%Y'), '$_POST[PETROCARD]', '$_POST[pcform]', STR_TO_DATE('$_POST[petexp]','%d/%m/%Y'), '$_POST[ContactNumber2]','$_POST[Peraddress]','$_POST[cname]','$_POST[relation]','$_POST[child]','$_POST[mobile]','$_POST[hometele]','$_POST[nfamily]','$_POST[sname]','$_POST[scountry]','$_POST[syear]','$_POST[scompleted]','$_POST[sgrade]','$_POST[Dname]','$_POST[Dcountry]','$_POST[Dyear]','$_POST[Dcompleted]','$_POST[Dgrade]','$_POST[Gname]','$_POST[Gcountry]','$_POST[Gyear]', '$_POST[Gcomleted]', '$_POST[Ggrade]','$_POST[oname]','$_POST[oyear]','$_POST[ocountry]', '$_POST[ocompleted]', '$_POST[ograde]');"))
{
	
	echo "Record Inserted Susscessfully!!!";

}
else
echo "Error:".mysqli_error($con);
}


else if($_GET[mode]=='delete')
{
$sql="DELETE from empinfo where EntryID='$_POST[EntryID]'";



if(!mysqli_query($con,$sql))
 {
  die('Error: ' . mysqli_error($con));
  }
echo "Record Deleted Susscessfully!!!";

}

?>

