关于数据库查询的IF语句不会执行

   <?php

if(empty($_POST) === false){
        $required_fields = array('teacher_id','class_id','startyr','endyr');
        foreach($_POST as $key=>$value){
            if(empty($value) && in_array($key, $required_fields)===true){
                $errors[]='Fields marked with an asterisk are required';
                break 1;
            }
        }if(empty($errors)===true){
            if(sched_exists($_POST['class_id'],$_POST['teacher_id'],$_POST['student_id']) === true){
                $errors[]='Schedule Already Exist!';

            }

        }   
    }
 ?>
<div class="container alert" id="showError">
 <?php


 if(empty($_POST) === false && empty($errors) === true){

 $cl_id=mysqli_real_escape_string($_POST['class_id']);
 $teacher_id=mysqli_real_escape_string($_POST['teacher_id']);
 $student_id=mysqli_real_escape_string($_POST['student_id']);
 $startyr=mysqli_real_escape_string($_POST['startyr']);
 $endyr=mysqli_real_escape_string($_POST['endyr']);

        $q="INSERT INTO sched(cl_id,teacher_id,student_id,startyr,endyr)
        values('{$cl_id}','{$teacher_id}','{$student_id}','{$startyr}','{$endyr}')";
    mysqli_query($q)or die(mysqli_error());

    mysqli_close($dbcon);
?>
<div class="alert alert-success">
<?php
    echo "<strong>Successfully Created!</strong> ";
?>
</div>
<?php 


    }else{
        echo output_errors($errors);
    }
?>
</div>
function sched_exists($cl_id,$teacher_id,$student_id){
    $cl_id;
    $teacher_id;
    $student_id;
    return (mysql_result(mysql_query("SELECT COUNT(`sched_id`) FROM `sched` WHERE `cl_id` = '$cl_id' AND `teacher_id` = '$teacher_id'"),0)==1) ? true : false or die(mysql_error());
    } 

can you tell me whats wrong? The if statement with the query to database wont execute and if i remove the if statement of sched exist the query will execute. i dont know whats the problem. Help me please

empty($_POST) is never false. better ask for if ( count($_POST) == 0)

mysql_result(result,0) returns the value of the first column of the first row of the result. This will probably not be 1 unless it happens that the first row is an ID column and the first result happens to have an ID of 1. You really should be doing something like:

$result = mysql_query(/*your query*/);
if ($result) return true;
else return false;