<?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 `ratemaster` SET `compid` = '$_POST[compid]', `vehtype` = '$_POST[vehtype]', `city` = '$_POST[city]', `package` = '$_POST[package]', `pkgrate` = '$_POST[pkgrate]', `darate` = '$_POST[darate]', `narate` = '$_POST[narate]', `exhrrate` = '$_POST[exhrrate]', `exkmrate` = '$_POST[exkmrate]' WHERE `entryid` = $_POST[ID]"))
//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);
}


if($_GET['mode']=="insert")
{
$qry=mysqli_query($con,"select entryid from master where `compid` = '$_POST[compid]' and `vehtype` = '$_POST[vehtype]' and `city` = '$_POST[city]' and `package` = '$_POST[package]'");
if(mysqli_num_rows($qry)>0)
die('Error :Master Already Exits!!');	
if(mysqli_query($con,"INSERT INTO `ratemaster` (`entryid`, `compid`, `vehtype`, `city`, `package`, `pkgrate`, `darate`, `narate`, `exhrrate`, `exkmrate`) VALUES (NULL, '$_POST[compid]', '$_POST[vehtype]', '$_POST[city]', '$_POST[package]', '$_POST[pkgrate]', '$_POST[darate]', '$_POST[narate]', '$_POST[exhrrate]', '$_POST[exkmrate]')"))
{
	echo "Record Inserted Susscessfully!!!";

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


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



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

}

?>

