OK, I know this is in here somewhere but can’t seem to find it.
What I have is a form to enter data into my mySQL database. When the form is complete (and error free), I want to user to be directed back to the same form. However, I get the " Cannot modify header information - headers already sent by " warning and the script stops.
How can I change that? I can put the code here but it is quite big and not sure how much or what part is relevant for this discussion.
It sounds like you are submitting the form to another page to do the processing and then trying to use a header redirect to go back to the form. The redirect would have to happen before anything is sent to the browser. Nothing can be output before using header.
You could also submit the form page to itself and do all the processing on the form page. Then there would be no need to redirect back to it.
Yes, clear the form and ready for new data. Sorry, but got another thing going so was trying to hurry.
At the beginning of the page, I have the line " if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) " with the else to display the form with blank values. Just mentioning this in case it makes a difference.
How much?? It is pretty long so am giving only the first part - not sure again how much is necessary. This is the beginning of the form with the stuff to validate it at the bottom of the form (much later since there is 10 input fields).
Try changing the following. Assuming you are using the $formValues variable to populate the form values this should fix the issue. If you are populating the form values using the $_POST values directly this wont work.
ProcessForm($formValues);
/*Add this line to clear you form values after they are processed*/
unset($formValues);
/*Remove the following line*/
//header("Location: ".$_SERVER['PHP_SELF']);