First of all, you have to take into account, that phalanxes are defensive units. So if you fight a phalanx with and equal phalanx, march them close to the other one and then order them to halt (by pressing backspace). The phalanxes will then lock fronts. This is all. Do not order them to attack because their strength is defense not offense. Only do that if your facing inferior phalanxes (like levy or kleruchoi phalanxes with pezhetairoi) or if you have an advantage in numbers or terrain. If you have phalanxes, always bring some flanking units like peltasts or better thureophoroi with you.