<?php                                                                        
    $miscellaneous="";
    if(isset($_POST['submit'])){
        //Function to sanitize values received from the form. Prevents SQL injection
        function clean($str) {
    		$str = @trim($str);
    		if(get_magic_quotes_gpc()) {
    			$str = stripslashes($str);
    		}
    		return mysql_real_escape_string($str);
    	}
        $miscellaneous = clean($_POST['miscellaneous']);
        
        if(!$staffID){
            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">Error: Failed to identify librarian!</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' ");
            $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("INSERT INTO miscellaneous (name,added,staffID,added_by)
                                            VALUES ('$miscellaneous',NOW(),'$staffID','$stafNo')"))
                {
                    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{
                    
                    $_SESSION["new"]='True';
                    header('Location:add-miscellaneous.php');
                    echo "<script type='text/javascript'> document.location = 'add-miscellaneous.php'; </script>";
                    exit();
                }
            
            }
        }
    }
?>                                                             