first off, make sure display_errors is turned on, make sure error_reporting is E_ALL.
if you are using any code that affects headers (cookies, sessions, header function calls) they must happen prior to any output, be it text, whitespace, anything; otherwise, you will get errors and warnings about headers being already sent, which will make your cookie/sessions/header calls not work. read
Warning: Cannot add header information for additional information about the errors, and how to fix them.
next, make sure to read
Posting Code in the Forums for our guidelines about posting bits of code/output what have you.
Finally, it is suggested that you do all php processing outside of "presentation" level things. In other words, 99.9999% of your php code should occur prior to any HTML. This is mostly to get the greatest seperation from the HTML and php as possible. The reason for this, is the page design will change, how the code works (behind the scenes) shouldn't change much at all in respect to the changing design. Plus, a designer can be working on the HTML while a programmer can work on the code without any overstep. Which is always productive.