<?php
 	session_start(); 
	

	if(!isset($_SESSION['tulsilogin']))
	{
		header('Location: index.php');
		return;
	}



$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	
	include("connect.php");
include("mylibrary.php");
	
	//$branchname=$_POST['branchname'];
	
	$branchname=checkvalidstring($_POST['branchname']);
	
	
	$branchaddress=checkvalidstring($_POST['branchaddress']);
	
	$countrymid=str_replace ("'","\'",$_POST['countrymid']);
	$countrymid=str_replace ('"','\"',$countrymid);
	
	$statemid=str_replace ("'","\'",$_POST['statemid']);
	$statemid=str_replace ('"','\"',$statemid);
	
	$citymid=str_replace ("'","\'",$_POST['citymid']);
	$citymid=str_replace ('"','\"',$citymid);
	
	
	$branchphone=checkvalidstring($_POST['branchphone']);
				
	
	$branchmobile=checkvalidstring($_POST['branchmobile']);
				
	
	$branchemail=checkvalidstring($_POST['branchemail']);
				
	
	$branchskype=checkvalidstring($_POST['branchskype']);
				
	
	$branchwhatsapp=checkvalidstring($_POST['branchwhatsapp']);
				
	
	$branchhead=checkvalidstring($_POST['branchhead']);
				
				
	
	$branchheadcontact=checkvalidstring($_POST['branchheadcontact']);
				
	
	$branchnote=checkvalidstring($_POST['branchnote']);
	
	$attechment="";
	/* if(empty($_FILES['attechment']['name']) == false  )
	{
		$attechment = date("YmdHis").$_FILES['attechment']['name'];
		$path = "docs/";
		move_uploaded_file( $_FILES['attechment']['tmp_name'], $path ."/". $attechment );
	
	}
	 */
	
	
		
	 $eve = "select * from res_branch_master where branchname='$branchname'";
	
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg'] = "branch Already Inserted.";
		header('Location: branch.php');
	}
	else
	{	
	 $eve1 = "INSERT INTO res_branch_master (branchname, branchaddress , countrymid , statemid, citymid, branchphone, branchmobile, branchemail , branchskype , branchwhatsapp, branchhead ,branchheadcontact , branchnote) VALUES('$branchname','$branchaddress','$countrymid','$statemid','$citymid',' $branchphone','$branchmobile','$branchemail','$branchskype',' $branchwhatsapp','$branchhead','$branchheadcontact','$branchnote')";
		
		$re1 = mysqli_query($conn, $eve1);
			
	$_SESSION['msg'] = "Record saved successfully";
	header('Location: branch.php');
			
	}
?>