Shouldn't "Der Student hat die Lehrerin gern" also be correct? "Gernhaben" definitely is one way to say "to like", the more common one in fact.
Why "den Lehrer"? Lehrer is masculine, so shouldn't it be "dem Lehrer"?
Here, Lehrer is in the akusativ (direct object) case, which makes the article "den". "Dem" is for dativ (indirect object) case.
Can't I say:
Der Lehrer gefällt dem Student?
Why not: den proffesor?
Because that would not be a correct translation of "teacher". For that, we have "lehrer", or "lehrerin" in case it's a female.