php变量值检查语句是否工作

As a beginner in php I`m getting stuck in such apparently simple looking problems given below.

I have a function called checkAvailability(), it takes two parameters and returns true or false.

$check = checkAvailability($name,$appointmentDate);

    if($check){

      $sql = "INSERT into appointments(Name,Address,Phone,Car_license_No,Car_Engine_No,Date,Mechanic) value('$name','$address','$phone','$license','$engine','$appointmentDate','$mechanic');";

    if(mysqli_query($db,$sql) == TRUE){

        echo '<script type="text/javascript">';
        echo 'alert("Submission Done");';
        echo '</script>';
    }
    else{

        echo '<script type="text/javascript">';
        echo 'alert("Submission Failed");';
        echo '</script>';
    }
    }

Data should get stored in database only when $check is true. The checkAvailability()is as follows,

function checkAvailability($mechanicName,$date){

        global $justin;

        if($mechanicName == 'Justin'){
            if($justin < 4){
                $justin++;
            }
            else{
                echo '<script type="text/javascript">';
                echo 'alert("Justin is not available");';
                echo '</script>';
                return false;
            }

            for($i=0;$i<count($dateJustin);$i++){
                if($date == $dateJustin[$i]){
                    echo '<script type="text/javascript">';
                    echo 'alert("Choose another date");';
                    echo '</script>';
                    return false;
                }
            }

            $dateJustin[$j] = $date;
            $j++;

            return true;
        }
    } 

The problem is in the function. I have checked that while running it reaches inside the function but it does not enter the if block if($mechanicName == 'Justin') though I am entering the name Justin as input each time.

Searched for relevant answers but none of those worked for me. Thanks in advance.