MySQL Insert with Select
Please try this: 

INSERT INTO class_teachers_section(class_ref, teachers_ref, section_ref) 
SELECT a.class_ref, b.teachers_ref, c.section_ref
      FROM
      (select class.id as class_ref from class where class.name = 'pe') as a,
      (select teachers.id as teachers_ref from teachers where teachers.last_name = 'lenevo') as b, 
      (select section.id as section_ref from section where section.name = 'grade 4') as c;


I assume it will be quiet slow, but should to the trick.