<?php
include "config.php";
if (isset($_POST['update'])) 
    {
        
        extract($_POST);

        $state1=$_POST['state'];
         $state=ucwords(strtolower($state1));
        $coulmn=array();
        $query1=mysqli_query($connect,"select * from tbl_state where fld_state_id!='".$_GET['fld_state_id']."' and fld_state_delete='0'");
        while ($row=mysqli_fetch_assoc($query1))
        {
          $coulmn[]=$row['fld_state_name'];
        }

        

		if (in_array($state, $coulmn)) 
		{
			echo '<script type="text/javascript">'; 
			echo 'alert("State Is Already Exist");';
			echo "window.location.href = 'view_state.php';";
			echo '</script>'; 
			return true;

		}    
        else
        {

            $query="Update tbl_state set fld_state_name='".$state."' where fld_state_id='".$_GET['fld_state_id']."' ";
            //echo $query."<br>";
            $row=mysqli_query($connect,$query) or die(mysqli_error($connect));
            if ($row) 
            {
                echo "<script>";
                echo "alert('State Updated Successfully');";
                echo "window.location.href='view_state.php';";
                echo "</script>";                 
            }
            else
            {
                echo "<script>";
                echo "alert('State Not Update.);";
                echo "window.location.href='view_state.php';";
                echo "</script>";
            }
        }    
    }
?>