<?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]'");
if(mysqli_num_rows($qry)>0)
die('Error :Master Already Exits!!');
$sql="INSERT INTO `master` ( `entryid`, `mstype`, `code`, `desc`, `det`, `det1`,`det2`, `det3`, `det4`) VALUES ('','$_POST[mstype]','$_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 Successfully!!";

}


else if($_GET[mode]=='update')
{
$sql="UPDATE `master` SET  `mstype` = '$_POST[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 Successfully!!!";

}


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



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

}

else if($_GET[mode]=='delete_product')
{
$sql="DELETE from prodreg where id='$_POST[id]'";



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

}






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

$sql="INSERT INTO `rawmatreg` ( `entryid`, `code`, `skuid`, `category`, `desc`, `color`,`size`, `qty`, `unit`, `psrate`, `pamount`) VALUES ('','$_POST[code]','$_POST[skuid]','$_POST[cate]','$_POST[desc]','$_POST[color]','$_POST[size]','$_POST[qty]','$_POST[unit]','$_POST[psrate]','$_POST[pamount]')";

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

echo "Record Added Successfully!!";

}


else if($_GET[mode]=='rowupdate')
{
$sql="UPDATE `rawmatreg` SET  `code` = '$_POST[code]', `skuid` = '$_POST[skuid]', `category` = '$_POST[cate]', `desc` = '$_POST[desc]',`color` = '$_POST[color]',`size` = '$_POST[size]', `qty` = '$_POST[qty]', `unit` = '$_POST[unit]', `psrate` = '$_POST[psrate]', `pamount` = '$_POST[pamount]'  WHERE entryid= '$_POST[entryid]'";



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

}


else if($_GET[mode]=='rowdelete')
{
$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);
?>
