apw Posted July 29, 2012 Share Posted July 29, 2012 Hello I have a php page called potato for.php with 3 different submit buttoms on it which are called auction, sell and cancel. At the bottom of the page i have this for each of the 3 submit buttoms: To tell the code what to do after the user selects one of the forrms buttons If (isset($_post["auction"])) { Now that i have this my question is with these how do i redirect the user to a page like auction.php or to barn.php without using a javascript to do so Thanks I Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/ Share on other sites More sharing options...
Christian F. Posted July 29, 2012 Share Posted July 29, 2012 Do all of the PHP parsing at the very top of the page, and then use variables to store the output. Doing it this way will ensure that you don't get the dreaded "headers already sent" error message, and it will make it a lot easier to write code. Once you've done that, it's just a matter of using following: header ('Location: new_file.php'); die (); Remember the "die ()" after a redirect, otherwise PHP will continue parsing the script and potentially create problems. Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/#findComment-1365210 Share on other sites More sharing options...
apw Posted July 29, 2012 Author Share Posted July 29, 2012 I have the session_start() posted at the very top of the page where the form is located and when i went to click on the link i got the cannot modify headers ... The session_start is before any othwr code is even started including where i tell the script the database name and info. Im not sure now what the problem iis Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/#findComment-1365215 Share on other sites More sharing options...
Pikachu2000 Posted July 29, 2012 Share Posted July 29, 2012 It probably isn't session_start() causing the error. What does the error message say exactly? Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/#findComment-1365216 Share on other sites More sharing options...
apw Posted July 29, 2012 Author Share Posted July 29, 2012 The exact error message iis: Warning: cannot send header information - headers already sent by (output startpotato.phped at potato.php:60) in potato.php on line 118. If its refering to line 60 this line has a <?php to start a new batch of php code Line 118 has this: header("location: sell.php"); die(); Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/#findComment-1365218 Share on other sites More sharing options...
Christian F. Posted July 29, 2012 Share Posted July 29, 2012 Tip: Look at the name of the function you're using. Should be quite informative when compared to the error message. Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/#findComment-1365244 Share on other sites More sharing options...
NLT Posted July 29, 2012 Share Posted July 29, 2012 Are you displaying anything before the header? Can you give us some code to look at please. Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/#findComment-1365250 Share on other sites More sharing options...
apw Posted July 29, 2012 Author Share Posted July 29, 2012 Here is the potatoplant.php that is giving me problems Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/#findComment-1365275 Share on other sites More sharing options...
Christian F. Posted July 29, 2012 Share Posted July 29, 2012 You've listed the reason yourself, in this post. Also, have you read this thread? http://forums.phpfreaks.com/index.php?topic=37442.0 Quote Link to comment https://forums.phpfreaks.com/topic/266404-using-php-to-redirect-after-a-form/#findComment-1365278 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.