A space toilet, or zero gravity toilet, is a toilet that can be used in a weightless environment. Where there is no gravity, the collection and retention of liquid and solid waste is directed by use of air flow. Since the air used to direct the waste is returned to the cabin, it is filtered beforehand to control odor and cleanse bacteria.
In older systems, waste water is vented into space, and any solids are compressed and stored for removal upon landing. More modern systems expose solid waste to vacuum pressures to kill bacteria, which prevents odor problems and kills pathogens.
The water waste which was disposed off into the space used to freeze and become solid floating debri; one of the reasons for the damage sustained by the external parts of the shuttle.
As for peeing, each astronaut is given his or her own funnel, made in different shapes for men and women, which attaches to a hose on the toilet. But as gravity diminishes in space, ego apparently doesn't.
Source = "European Space Agency, ESA"
Today, going to the bathroom in space is much less tedious, but it still requires careful attention, and even space toilet training. The reusable space planes of NASA's retired shuttle program had toilets using airflow to draw waste away from the body in place of Earth's gravity. The International Space Station has commodes with a similar design.
Space toilets didn't become much more sophisticated by the time the first Apollo missions launched. Astronauts like Buzz Aldrin and Neil Armstrong had fecal collection bags that stuck to their bottoms with adhesive when they had to go. And microgravity could make things messy.
A next-generation space toilet called the Universal Waste Management System (UWMS) is being developed by NASA for Orion and other long duration missions. It is planned to be quieter, lighter, more reliable, more hygienic and more compact than previous systems. A flight test article of the UWMS is planned to be delivered and tested on the ISS in 2018.