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


if($_GET[mode]=='insert')
{    

		$sql="INSERT INTO `rawmatreg` (`entryid`, `code`, `desc`, `unit`) VALUES ('','$_POST[rmcode]','$_POST[description]','$_POST[unit]')";
		
		 if(!mysqli_query($con,$sql))
		   {
			die('Error: ' . mysqli_error($con));
			}
		echo "Record Added Successfully!!";
		
		   
}




else if($_GET[mode]=='update')
{
	
		
		  $sql="UPDATE `rawmatreg` SET  `code` = '$_POST[rmcode]',`desc` = '$_POST[description]', `unit` = '$_POST[unit]'  WHERE entryid= '$_POST[EntryID]'";
		  
		  if(!mysqli_query($con,$sql))
		   {
			die('Error: ' . mysqli_error($con));
			}
		  echo "Record Updated Successfully!!!";


}



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



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

}
mysqli_close($con);
?>
