query("SELECT * FROM school WHERE specific_sAdminCode = '$newCode'"); // if($result->num_rows > 0){ // //this means code is already taken // echo "0"; // }else{ // //this means code is available // echo "1"; // } //First we check if the code is taken $result = $conn->query("SELECT * FROM school WHERE specific_sAdminCode = '$newCode'"); if($result->num_rows > 0){ echo "0"; }else{ $result = $conn->query("SELECT * FROM school WHERE specific_teacherCode = '$newCode'"); if($result->num_rows > 0){ echo "0"; }else{ $result = $conn->query("SELECT * FROM school_class WHERE specific_classCode = '$newCode'"); if($result->num_rows > 0){ echo "0"; }else{ echo "1"; } } } $conn->close(); ?>