A direct connection between the engine and the road wouldn't provide enough torque at the wheels to get the car moving. And even if it did, the engine would quickly run out of revs. So the gearbox provides a range of gearing, to multiply the engine's torque to overcome the car's inertia and get it moving, as well as providing it with a reasonable speed capability. It also allows the car to do this in a straight line, as well as going round corners.
There are three main types of gearbox:
The typical FWD unit is compact and will house the gears (known as the gear set, kit or cluster), the final drive and the differential. Typically, there will be two shafts with gears on them - an input shaft and below it, an output shaft. Each pair of gears is constantly meshing, but only one pair is fixed to the shafts at any time.
A typical RWD gearbox will have three shafts - input, lays haft and output. The input and output shafts run in line with each other but are mechanicaily separated. The layshaft sits beneath the two and overlaps them. The input shaft constantly drives the layshaft through a pair of meshing gears, this is 'constant mesh'. The layshaft and output shaft have the pairs of gears rotating on them and from the constant mesh gearing onwards, it behaves in a similar way to the FWD gearbox. The main extra aspect is that if the box features a direct ratio, usually fourth, there will be a system to lock the two shafts together, bypassing the gear cluster.