Hi guys, I have a form page where I want to send the user back to the same page if a condition is not met. I've tried header("Location: url"); as suggested in the book I'm using, but that results in an error (cannot modify header - already sent). So, having done a bit of research, it would appear I'm using that the wrong way. What should I be doing? As always, you guys rock, and much appreciated.
Hello, If you turn output buffering on (put ob_start() at the VERY top of your code), you can avoid this error. The problem is being caused by you outputting content, then trying to redirect via the headers. Output buffering will hold everything in the buffer, and flush it all at once (so you can send headers after content), for the price of a page loading delay (i.e. it will all load at once). Jay
You may not send anything before you send the header. Make sure that you don't echo or print anything before and it should work as expected. Jean-Luc
Or you could make your php code output some javascript with a document.location type redirect. Ugly but it would work the way you're trying to use it.
I personally had a lot of problems with that and I discoverd that you need to put this command on the top of the page (line 1 of code or so)!
I personally think it would be better if you actually output the form again and print an error that the condition is not met !! it would also be better if this 'new' form also has some of the entries user already did. you already have an answer for Location header not working