<?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 `usermst` SET `userid` = '$_POST[userid]', `loginname` = '$_POST[loginname]',`pwd` = '$_POST[pwd]', `dept` = '$_POST[dept]', `design` = '$_POST[design]', `branch` = '$_POST[branch]',   `callreg` = '$_POST[callreg]', `billing` = '$_POST[billing]',`report` = '$_POST[report]', `masters` = '$_POST[masters]', `vehicle` = '$_POST[vehicle]' , `voucher` = '$_POST[voucher]'  WHERE `usermst`.`id` = $_POST[ID] "))
//echo "$_POST[userid]###$_POST[loginname]###$_POST[pwd]###$_POST[dept]###$_POST[desg]###$_POST[mobile]###$_POST[firstname]###Record Updated Successfully!!!";

echo "Record Updated Successfully!!!";


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


if($_GET['mode']=="insert")
{
$qry=mysqli_query($con,"select id from empinfo usermst `userid` = '$_POST[userid]' or `loginname` = '$_POST[loginname]'");
if(mysqli_num_rows($qry)>0)
die('Error :Userid / Username Already Exits!!');	
	
if(mysqli_query($con,"INSERT INTO `usermst` (`id`, `userid`, `loginname`, `pwd`, `dept`, `design`,`branch`, `callreg`,  `billing`,`report`, `masters`,`voucher`) VALUES (NULL, '$_POST[userid]', '$_POST[loginname]', '$_POST[pwd]', '$_POST[dept]', '$_POST[design]','$_POST[branch]', '$_POST[callreg]','$_POST[billing]', '$_POST[report]', '$_POST[masters]','$_POST[voucher]')"))
{
	echo "Record Inserted Successfully!!!";

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

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



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


}


?>

