<?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");


	
	$statemid=$_POST['statemid'];
	$statename=checkvalidstring ($_POST['statename']);
	
	
	$statecode=checkvalidstring ($_POST['statecode']);
	$countrymid=$_POST['countrymid'];
	
	$tt="";
	/* if(empty($_FILES['attechment']['name']) == false  )
	{
		$attechment = date("YmdHis").$_FILES['attechment']['name'];
		$path = "docs/";
		move_uploaded_file( $_FILES['attechment']['tmp_name'], $path ."/". $attechment );
	
		$tt = ",attechment='$attechment' ";
	} */

	$eve = "select * from res_state_master where statecode='$statecode' and statemid!=$statemid";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg1'] = "state Already Inserted.";
		header('Location: state.php');
	}
	else
	{

	 $eve1 = "update res_state_master set statename='$statename', countrymid='$countrymid', statecode='$statecode' $tt where statemid='$statemid'";

	

	if ($conn->query($eve1) === TRUE)

	{		

		$_SESSION['msg'] = "state Record Updated succesfully";

		header('Location: state.php');		

	} 

	else 

	{

			

		$_SESSION['msg'] = "Error";

		header('Location: state.php');

	}
	}

?>