<?php
 	session_start(); 

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



$_SESSION['_token']=bin2hex(openssl_random_pseudo_bytes(16));
	
	
	include("connect.php");

	
	//$countryname=$_POST['countryname'];
	$countryname=str_replace ("'","\'",$_POST['countryname']);
	$countryname=str_replace ('"','\"',$countryname);
	
		$countrycode=str_replace ("'","\'",$_POST['countrycode']);
	$countrycode=str_replace ('"','\"',$countrycode);
	$countrycurrency=str_replace ("'","\'",$_POST['countrycurrency']);
	$countrycurrency=str_replace ('"','\"',$countrycurrency);
	
	
	$attechment="";
	if(empty($_FILES['file11']['name']) == false  )
	{
		$simplephoto11=$_FILES['file11']['name'];
		$ext = pathinfo($simplephoto11, PATHINFO_EXTENSION);
		$fileexplode1 = explode(".",$simplephoto11);
		$fileend1 = end($fileexplode1);

		 $filename= date("YmdHis").rand(100,999).".".$fileend1;
		
		
		$path = "docs";
		move_uploaded_file( $_FILES['file11']['tmp_name'], $path ."/". $filename );
	}
	
	
		
	$eve = "select * from res_country_master where countryname='$countryname'";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg1'] = "country Already Inserted.";
		header('Location: country.php');
	}
	else
	{	
		$eve1 = "INSERT INTO res_country_master (countryname, attechment,countrycode,countrycurrency) VALUES('$countryname','$filename','$countrycode','$countrycurrency')";
		$re1 = mysqli_query($conn, $eve1);
			
	$_SESSION['msg'] = "Record saved successfully";
	header('Location: country.php');
			
	}
?>