为什么这个变量保持正确?

I try to create a field validator by PHP. I want to change an index global variable to check it later for execute my query, and also i want to change my elements directly. BUT my index variable not chang when happend a error! Check Me Please!

<?php

$isValid=1;

function validation($indexForm,$inputName,$require,$type,$tblName=NULL,$fldName=NULL){
    
    global $isValid;
    if(isset($_POST[$indexForm])){
        
    if($require==1||$require==true){
    if(!isset($_POST[$inputName]) || $_POST[$inputName]==''){
            $isValid=0;
            echo " style='border:solid red 1px;' title='Fill Required' ";
            }
        }
        
    if($type=='int' && isset($_POST[$inputName]) && $_POST[$inputName]!='' && filter_var($_POST[$inputName],FILTER_VALIDATE_INT)===false ){
            $isValid=0;
            echo "style='border:solid red 1px;' title='Integer Required'";
            }
    if( $tblName && $fldName ){
            if(mysqli_num_rows(query("select * from `".$tblName."` where ".$fldName."='".$_POST[$inputName]."';"))!=0){
                $isValid=0;
                echo " style='border:solid red 1px;' title='Unique Required'";
            }
            }
}
return;
}

?>

</div>