<?php
	//Connects to your Database
		include "../db_connection/db_connection.php";
		include "../config/config.php";
		$category		=	$_POST['category']; 
		$category_type	=	$_POST['category_type']; 
		$cat_name		=	$_POST['cat_name']; 
		$short_frm		=	$_POST['short_frm']; 
		$cat_exp		=	$_POST['cat_exp']; 
		$cost_vl		=	$_POST['cat_cst'];

		$SLCT_chk ="SELECT master_cat_id FROM master_cat WHERE  cat_name='$cat_name' and category='$category'";
		$QURY_chk = mysqli_query($connect,$SLCT_chk);
		$FTCH_chk = mysqli_num_rows($QURY_chk);
		//exit;
		if($FTCH_chk==0){

		$SLCT_sk = "SELECT master_cat_id FROM master_cat WHERE master_cat_name LIKE '$short_frm' ORDER BY master_cat_id ASC";
		$QURY_sk = mysqli_query($connect,$SLCT_sk);  
		$FTCH_sk = mysqli_fetch_object($QURY_sk); 
		$FTCH_row = mysqli_num_rows($QURY_sk);
		$parent_id=0;
		if($FTCH_row>0){
			$parent_id=$FTCH_sk->master_cat_id;
		}


		$INSRT = "INSERT INTO master_cat(`parent_id`,`category`,`master_cad_type_id`,`cat_name`,`master_cat_name`,`cat_expantion`,`cost_vl`, `post_dt`) VALUES ('$parent_id','$category','$category_type','$cat_name','$short_frm','$cat_exp','$cost_vl','$cur_time')";
		//echo $INSRT;
		//exit;
		$QURY = mysqli_query($connect,$INSRT);

?>
		<script type="text/javascript">
            alert("Data inserted successfully");
            //history.back();
            window.location='../master_category_list.php';
        </script>
		<?php } else { ?>
		<script type="text/javascript">
            alert("Category Name already exists!!!");
            //history.back();
            window.location='../master_category_add.php';
        </script>
		<?php } ?>
	
