I told you: Save a debugging session, split your system into multiple scripts.
Trying to shove an entire application into a single PHP script is a pain in the ass.
Also don't ask me to tell you what's going wrong without telling me what's going wrong.