Fischer to Haworth projection: which carbon connects to the oxygen? For D-erythose, carbon 4, (the last carbon), connects to the O which connects to Carbon 1.



However, for D-glucose, carbon 5 (the 2nd last carbon) attaches to the O which attaches to carbon 1. 



Why is it the last carbon for D-erythose but the second last carbon for D-glucose that is connected to the oxygen in the Haworth projection? How do I decide which one gets connected when trying to convert Fischer to  Haworth projections?
It just is. There are pyranose and furanose forms for all aldoses and hexoses (given they are long enough), including glucose:

$\hspace{3cm}$

You will just have to remember which connections correspond to which sugars. You can read more about anomers ($\alpha$ vs. $\beta$) here, and more about carbohydrate chirality (D vs. L) here.