<?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");
	$departmentmid=$_POST['departmentmid'];
	$dname=checkvalidstring($_POST['departmentname']);
	
	
	
	 $eve = "select * from res_department_master where departmentname='$dname' and departmentmid != $departmentmid";
	$re = mysqli_query($conn, $eve);
	if(mysqli_num_rows($re) > 0)
	{
		$_SESSION['msg1'] = "Department Already Inserted.";
		header('Location: department.php');
	}
	else
	{	
	$eve1 = "update res_department_master set departmentname='$dname' where departmentmid = $departmentmid";
	
	
	if ($conn->query($eve1) === TRUE)
	{
			
		$_SESSION['msg'] = "Record has been updated successfully";
		header('Location: department.php');
			
	}
	}
?>