<?php  
    $miscellaneous="";
    if(isset($_POST['update']))
    {
        function clean($str) {
            $str = @trim($str);
            if(get_magic_quotes_gpc()) {
                    $str = stripslashes($str);
            }
            return mysql_real_escape_string($str);
    	}
        
        $miscellaneous = clean($_POST['miscellaneous']);
        $idd =  mysql_real_escape_string($_GET['id']);
        
        if(!$idd){
            echo'<div class="alert alert-danger absolue center text-center" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <span class="text-danger">Error occured while trying to fetch Miscellaneous info.</span>
                </div>';
        }else
        if(!$miscellaneous){
            echo'<div class="alert alert-danger absolue center text-center" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <span class="text-danger">Enter Miscellaneous Type</span>
                </div>';
        }else
        {
            $selectFee = mysql_query("SELECT * FROM miscellaneous WHERE name='$miscellaneous' AND miscellaneous != '$idd'");
            $countFee=  mysql_num_rows($selectFee);
            
            if($countFee > 0 ){
                echo'<div class="alert alert-warning absolue center text-center" role="alert">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                        <span class="text-warning"> 
                            <b><i class="fa fa-warning"></i> &nbsp; Warning</b>
                            <br>
                            This miscellaneous already exists
                        </span>
                    </div>';
            }else
            {
                if(!$insert = mysql_query("UPDATE miscellaneous SET name='$miscellaneous',updated_by='$stafNo' WHERE miscellaneousID='$idd'")){
                    echo'<div class="alert alert-danger absolue center text-center" role="alert">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                            <span class="text-danger">'.mysql_error().'</span>
                        </div>';
                }else
                {
                    $miscellaneous="";
                    $_SESSION['update_success']="true";
                    header('Location:miscellaneous.php');
                    echo "<script type='text/javascript'> document.location = 'miscellaneous.php'; </script>";
                    exit();
                }
            }
        }
       
    }  
?>