$_POST corrupted by ob_start
Posted: Sat Dec 12, 2009 10:54 pm
Hi There,
very new to PHP, so please be gentle with me
I have a problem with the $_POST array on a form (to edit user account details) that I've built:
The functioning of the form is:
1) A test is done to see if $_POST['submit'] is set
2) if it is set then the various form controls are validated and any errors result in a $_SESSION element being set with an error message and a header() function called to redisplay the form.
3) if $_POST['submit'] is not set then the db is read for the user ID stored in $_SESSION and the db fields are pre-loaded into other $_SESSION elements
4) The form is displayed - any error message is displayed at the top, and the form controls are displayed with their pre-loaded values from $_SESSION.
All quite straight forward. The problem is though that depending upon what values are entered into the form by the user (or even what field names on the form are used) the $_POST array may or may not be set when the Submit button is clicked.
I discovered eventually that by removing the ob_start() function call at the top of the php, the $_POST array would be set correctly 100% of the time. However this also caused further problems down the script when the validation section tried to issue a header() function call ('headers already sent' type of error).
I've looked and looked at the code, and everything seems ok. I've nearly torn out what little remains of my hair, so any suggestions would be greatly appreciated.
Thanks very much in advance
very new to PHP, so please be gentle with me
I have a problem with the $_POST array on a form (to edit user account details) that I've built:
The functioning of the form is:
1) A test is done to see if $_POST['submit'] is set
2) if it is set then the various form controls are validated and any errors result in a $_SESSION element being set with an error message and a header() function called to redisplay the form.
3) if $_POST['submit'] is not set then the db is read for the user ID stored in $_SESSION and the db fields are pre-loaded into other $_SESSION elements
4) The form is displayed - any error message is displayed at the top, and the form controls are displayed with their pre-loaded values from $_SESSION.
All quite straight forward. The problem is though that depending upon what values are entered into the form by the user (or even what field names on the form are used) the $_POST array may or may not be set when the Submit button is clicked.
I discovered eventually that by removing the ob_start() function call at the top of the php, the $_POST array would be set correctly 100% of the time. However this also caused further problems down the script when the validation section tried to issue a header() function call ('headers already sent' type of error).
I've looked and looked at the code, and everything seems ok. I've nearly torn out what little remains of my hair, so any suggestions would be greatly appreciated.
Thanks very much in advance