Added the endwhile and endif to correct php faults

Previously I had corrected the malformed if else block from lines 53 to 56 as the comments would probably end up as the only executed part of those blocks.