<?php
  include '../db_connect.php';
 foreach($_POST as $key => $value){
$_POST[$key] = mysqli_real_escape_string($con,trim($value));
}


if($_GET[mode]=='insert')
{
$qry=mysqli_query($con,"select entryid from master where `mstype` = '$_POST[mstype]' and `code` = '$_POST[code]' and `desc` = '$_POST[desc]'");
if(mysqli_num_rows($qry)>0)
die('Error :Master Already Exits!!');
$sql="INSERT INTO `servicemst` ( `entryid`, `mstype`, `code`, `desc`, `det`, `det1`,`det2`, `det3`, `det4`) VALUES ('',' ','$_POST[code]','$_POST[desc]','$_POST[det]','$_POST[det1]','$_POST[det2]','$_POST[det3]','$_POST[det4]')";

if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }

echo "record added succesfully!!";

}


else if($_GET[mode]=='update')
{
$sql="UPDATE `servicemst` SET  `mstype` = ' ', `code` = '$_POST[code]', `desc` = '$_POST[desc]', `det` = '$_POST[det]', `det1` = '$_POST[det1]',`det2` = '$_POST[det2]', `det3` = '$_POST[det3]', `det4` = '$_POST[det4]' WHERE entryid= '$_POST[entryid]'";



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

}


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



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

}


mysqli_close($con);
?>
