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

        $media1=$_POST['media'];
         $media=ucwords(strtolower($media1));
        $coulmn=array();
        $query1=mysqli_query($connect,"select * from tbl_media where fld_media_id!='".$_GET['fld_media_id']."' and fld_media_delete='0'");
        while ($row=mysqli_fetch_assoc($query1))
        {
          $coulmn[]=$row['fld_media_name'];
        }

        

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

		}    
        else
        {

            $query="Update tbl_media set fld_media_name='".$media."' where fld_media_id='".$_GET['fld_media_id']."' ";
            //echo $query."<br>";
            $row=mysqli_query($connect,$query) or die(mysqli_error($connect));
            if ($row) 
            {
                echo "<script>";
                echo "alert('Media Updated Successfully');";
                echo "window.location.href='view_media.php';";
                echo "</script>";                 
            }
            else
            {
                echo "<script>";
                echo "alert('Media Not Update.);";
                echo "window.location.href='view_media.php';";
                echo "</script>";
            }
        }    
    }
?>