Here's what i'm trying to do:
SITUATION 1 - On submitting to my page - thePage.php from a form i'd like to:
1. insert some stuff into a database.
2. redirect to another page - aPage.html.
SITUATION 2 - On submitting to thePage.php from a link i'd like to:
1. insert some stuff into a database.
2. display some information and not redirect.
What I've done is passed from the form and from the link a variable to indicate which type of submission it is (note the form submits as get for other reasons). I'm able to insert into the database for both situations but for SITUATION 1 I am unable to redirect.
I've tried the following line:
header("Location: http://localhost/LisaMarie/aPage.html");
but the following error is thrown:
Warning: Cannot modify header information - headers already sent by (output started at C:\htdocs\LisaMarie\thePage.php:83) in C:\htdocs\LisaMarie\thePage.php on line 167
My questions:
1. Why is this error occuring, I don't have any other header setting code?
2. Is there any other way - within php - to perform redirecting.
3. Are there other easily used redirecting code that can be partnered with php to work effectively eg. JavaScript.
PHP REDIRECT
Moderator: General Moderators
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
A very nicely formatted post. Unforunantely, this is one of the oft asked questions in PHP. Try: viewtopic.php?t=1157 (although it looks like the formatting has been borked).
About your other questions, you can use HTML META tags for "refresh" to redirect, you can also use JavaScript, although that path is not recommended.
Within PHP? You probably don't have a templating system. If you did, well, then it would be a matter of including the appropriate pages, but that's not recommended.
About your other questions, you can use HTML META tags for "refresh" to redirect, you can also use JavaScript, although that path is not recommended.
Within PHP? You probably don't have a templating system. If you did, well, then it would be a matter of including the appropriate pages, but that's not recommended.
1. That specific error will be thrown if anything, absolutely anything is printed to the screen prior to the header() function call. You can probably get around this by rethinking when the header() call is made.
2. With PHP you could forget the redirect and just have the page display a different set of content based on the form submission data.
So all though it isn't a true redirect, the page will look different to the user.
3. You could always window.location() in JS.
Hope that helps.
2. With PHP you could forget the redirect and just have the page display a different set of content based on the form submission data.
Code: Select all
if (isset($_POST['submit'])){
//content to display
} else {
//content to display
}3. You could always window.location() in JS.
Hope that helps.
-
lisamarie_tt
- Forum Commoner
- Posts: 32
- Joined: Fri Jul 15, 2005 8:20 am
Thank you all !!!!!!
I was able to immediately figure out the problem. I had some output that was beign displayed before the header statement. (It pays to comment all that you think will not affect general execution
)
My code works fine now, with the orginal syntax that I used.
Thanks Again for you assistance.
I was able to immediately figure out the problem. I had some output that was beign displayed before the header statement. (It pays to comment all that you think will not affect general execution
My code works fine now, with the orginal syntax that I used.
Thanks Again for you assistance.