<?php  
    $pass="";
    if(isset($_POST['submit']))
    {
        $pass = mysql_real_escape_string($_POST['pass']);
        
        if(!$pass){
            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 Gate Pass Type</span>
                </div>';
        }else 
        {
            if(!$select = mysql_query("SELECT * FROM pass WHERE name = '$pass'")){
                    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{
                $countrow=  mysql_num_rows($select);
                if($countrow > 0){
                    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: Gate Pass Type already exists!</span>
                            </div>';
                }else
                {
                    //generate course code
                    if(!$insert = mysql_query("INSERT INTO pass (name,added,added_by)VALUES('$pass',NOW(),'$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
                    {
                        $pass="";
                        $_SESSION['success']="true";
                        header('Location:add-pass.php');
                        echo "<script type='text/javascript'> document.location = 'add-pass.php'; </script>";
                        exit();
                    }
                }    
            }
        }
       
    }  
?>