<?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 `ledgerreg` SET `ledger` = '$_POST[ledger]', `alias` = '$_POST[alias]', `ledtype` = '$_POST[ledtype]', `openingbal` = '$_POST[openingbal]' WHERE `ledgerreg`.`id` = '$_POST[ID]';"))
echo "Record Updated Susscessfully!!!";

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


if($_GET['mode']=="insert")
{
if(mysqli_query($con,"INSERT INTO `ledgerreg` (`id`, `ledger`, `alias`, `ledtype`, `openingbal`) VALUES (NULL, '$_POST[ledger]', '$_POST[alias]', '$_POST[ledtype]','$_POST[openingbal]');"))
{
	echo "Record Inserted Susscessfully!!!";

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

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



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

}

?>

