The most obvius problem i see is that there are blank lines between php code blocks at lines 5, 6, and 8. these blank lines between php code blocks will cause the redirection to the cart page to fail. they should be deleted.
if you still have problems, I'll need to troubleshoot directly, see the private message section.