<?php

include '../db_connect.php';

if($_GET['mode']=="update")
{
if(mysqli_query($con,"UPDATE `prodreg` SET `code`  = '$_POST[code]' , `gencode`  = '$_POST[gencode]' , `color`  = '$_POST[color]' , `stock`  = '$_POST[stock]' , `reorder`  = '$_POST[reorder]' , `cat`  = '$_POST[cat]' , `sizesetcode`  = '$_POST[sizesetcode]' , `sets`  = '$_POST[set]' , `desc`  = '$_POST[desc]' , `unit`  = '$_POST[unit]' , `ptotal`  = '$_POST[ptotal]' , `pdiscount`  = '$_POST[pdiscount]' , `pnamount`  = '$_POST[pnamount]' , `vat`  = '$_POST[vat]' , `grtotal`  = '$_POST[grtotal]' , `status`  = '$_POST[status]' where 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 code from prodreg where code='$_POST[code]'");
if(mysqli_num_rows($qry)>0)
die('Error :Company Name Already Exits!!');

if(mysqli_query($con,"INSERT INTO `prodreg` SET `code`  = '$_POST[code]' , `gencode`  = '$_POST[gencode]' , `color`  = '$_POST[color]' , `stock`  = '$_POST[stock]' , `reorder`  = '$_POST[reorder]' , `cat`  = '$_POST[cat]' , `sizesetcode`  = '$_POST[sizesetcode]' , `sets`  = '$_POST[set]' , `desc`  = '$_POST[desc]' , `unit`  = '$_POST[unit]' , `ptotal`  = '$_POST[ptotal]' , `pdiscount`  = '$_POST[pdiscount]' , `pnamount`  = '$_POST[pnamount]' , `vat`  = '$_POST[vat]' , `grtotal`  = '$_POST[grtotal]' , `status`  = '$_POST[status]'"))
{
	$currid=mysqli_insert_id($con);
	echo "Record Inserted Susscessfully!!!###$currid";

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

}

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



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

}

?>

