<?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]', `cmpcity` = '$_POST[city]', `incstax` = '$_POST[incstax]',`inctoll` = '$_POST[inctoll]', `telephone` = '$_POST[telephone]', `email` = '$_POST[email]',`conper` = '$_POST[conper]',`type` = '$_POST[type]',`timestamp` = 'NOW()' WHERE `commst`.`id` = $_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 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 `ledgerreg` (`id`,`cmp`, `ledger`, `alias`, `ledtype`,`openingbal`,`timestamp`) VALUES (NULL, '$_POST[cmp]', '$_POST[ledger]', '$_POST[alias]', '$_POST[ledtype]','$_POST[openingbal]', 'NOW()');"))
{
	$currid=mysqli_insert_id($con);
	echo "Record Inserted Susscessfully!!!###$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 Susscessfully!!!";

}

?>

