<?php

include '../db_connect.php';

if($_GET['mode']=="update")
{
if(mysqli_query($con,"UPDATE `commst` SET `compid` = '$_POST[compid]', `name` = '$_POST[name]', `address` = '$_POST[address]' , `address1` = '$_POST[address1]' , `address2` = '$_POST[address2]', `cmpcity` = '$_POST[city]', `pincode` = '$_POST[pincode]', `incstax` = '$_POST[incstax]', `inctoll` = '$_POST[inctoll]', `telephone` = '$_POST[telephone]', `email` = '$_POST[email]', `conper` = '$_POST[conper]' ,`vat` = '$_POST[vat]' ,`tin` = '$_POST[tin]', `rtmst` = '$_POST[rateonp]', `rtvalue` = '$_POST[rtvalue]', `discount` = '$_POST[discount]', `panno` = '$_POST[panno]', `type` = '$_POST[type]',  `ftype` = '$_POST[ftype]', `tax` = '$_POST[tax]', `broker` = '$_POST[broker]', `gstin` = '$_POST[gstin]', `gsttype` = '$_POST[gsttype]', `state` = '$_POST[state]', `statecode` = '$_POST[statecode]', `consignee` = '$_POST[consignee]', `agent` = '$_POST[agent]'  WHERE `commst`.`id` = $_POST[ID] "))
//echo "$_POST[compid]###$_POST[name]###$_POST[address]###$_POST[city]###$_POST[incstax]###$_POST[telephone]###Record Updated Susscessfully!!!";
echo "Record Updated Successfully!!!";

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


if($_GET['mode']=="insert")
{
$qry=mysqli_query($con,"select id from commst where compid='$_POST[compid]'");
if(mysqli_num_rows($qry)>0)
die('Error :Company Name Already Exits!!');

if(mysqli_query($con,"INSERT INTO  `commst` SET `id` = '', `compid` = '$_POST[compid]', `name` = '$_POST[name]', `address` = '$_POST[address]' , `address1` = '$_POST[address1]' , `address2` = '$_POST[address2]', `cmpcity` = '$_POST[city]', `pincode` = '$_POST[pincode]', `incstax` = '$_POST[incstax]', `inctoll` = '$_POST[inctoll]', `telephone` = '$_POST[telephone]', `email` = '$_POST[email]', `conper` = '$_POST[conper]' ,`vat` = '$_POST[vat]' ,`tin` = '$_POST[tin]', `rtmst` = '$_POST[rateonp]', `rtvalue` = '$_POST[rtvalue]', `discount` = '$_POST[discount]', `panno` = '$_POST[panno]', `type` = '$_POST[type]',  `ftype` = '$_POST[ftype]', `tax` = '$_POST[tax]', `broker` = '$_POST[broker]', `gstin` = '$_POST[gstin]', `gsttype` = '$_POST[gsttype]', `state` = '$_POST[state]', `statecode` = '$_POST[statecode]' , `consignee` = '$_POST[consignee]', `agent` = '$_POST[agent]' "))
{
	$currid=mysqli_insert_id($con);
	echo "Record Inserted Successfully!!!###$currid";

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

}

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



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

}

?>

