As you realize, Islam has a very serious moral code. It does not approve of any sexual practices, outside marriage.
Islamic legislation includes very severe punishments for adultery.
To go to a prostitute earns the man the same severe punishment. When we want to know the answer Islam provides to a social problem, and prostitution is one, we have to consider Islamic society as a whole. In a Muslim society, no woman needs to work in order to earn her living. Many prostitutes are first drawn into this horrid practice by their poverty. Some girls find themselves having to earn the living of other people in their families, such as a sickly mother or young children.