<?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");
	
	//$countryname=$_POST['countryname'];
	$countryname=str_replace ("'","\'",$_POST['countryname']);
	$countryname=str_replace ('"','\"',checkvalidstring($countryname));
	$countrycode=str_replace ("'","\'",$_POST['countrycode']);
	$countrycode=str_replace ('"','\"',checkvalidstring($countrycode));
	$countrysortname=str_replace ("'","\'",$_POST['countrysortname']);
	$countrysortname=str_replace ('"','\"',checkvalidstring($countrysortname));
	
	$countrycurrency=str_replace ("'","\'",$_POST['countrycurrency']);
	$countrycurrency=str_replace ('"','\"',checkvalidstring($countrycurrency));
	
	
	$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_country_master where countrysortname='$countrysortname'";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg1'] = "countrycode Already Inserted.";
		header('Location: countrycode.php');
	}
	else
	{	
		 $eve1 = "INSERT INTO res_country_master (countryname,countrycode,countrysortname,countrycurrency) VALUES('$countryname','$countrycode','$countrysortname','$countrycurrency')";
		
		$re1 = mysqli_query($conn, $eve1);
			
	$_SESSION['msg'] = "Record saved successfully";
	header('Location: countrycode.php');
			
	}
?>