muppet77 Posted September 8, 2012 Share Posted September 8, 2012 hi, i am attempting to use a form to submit info which then determines a redirection to one of 2 urls. i can get the form appearing and submitting but the redirect doesn't happen. can someone please help? thanks in advance <?php if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form ?> <html> <head> <title>corners in running</title> </head> <body> <form method="post" action="<?php echo $PHP_SELF;?>"> Corners:<br /> 10:<input type="radio" value="10" name="wholecorners"> 11:<input type="radio" value="11" name="wholecorners"><br /> <input type="submit" value="submit" name="submit"> </form> <?php $corners = $_POST["wholecorners"]; if($corners>=10 && $corners<=10.99) {header('Location: http://maidenerleghweather.com/corners1.php?var1=' . $corners. '&var2='.$time ); } if($corners>=11 && $corners<=11.99) {header('Location: http://maidenerleghweather.com/corners2.php?var1=' . $corners. '&var2='.$time ); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/268149-header-form-then-redirect-fails/ Share on other sites More sharing options...
requinix Posted September 8, 2012 Share Posted September 8, 2012 Because you put the redirecting inside the "if the form hasn't been submitted" block. Quote Link to comment https://forums.phpfreaks.com/topic/268149-header-form-then-redirect-fails/#findComment-1376267 Share on other sites More sharing options...
muppet77 Posted September 8, 2012 Author Share Posted September 8, 2012 Thanks. Would you mind helping me correct it. I have hashed it together and am a beginner. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/268149-header-form-then-redirect-fails/#findComment-1376268 Share on other sites More sharing options...
Niixie Posted September 8, 2012 Share Posted September 8, 2012 Try the following: <html> <head> <title>corners in running</title> </head> <body> <form method="post" action="<?php echo $PHP_SELF."?post";?>"> Corners:<br /> 10:<input type="radio" value="10" name="wholecorners"> 11:<input type="radio" value="11" name="wholecorners"><br /> <input type="submit" value="submit" name="submit"> </form> <?php if($_POST['submit'] && isset($_GET['post'])) { $corners = $_POST["wholecorners"]; if($corners>=10 && $corners<=10.99) {header('Location: http://maidenerleghweather.com/corners1.php?var1=' . $corners. '&var2='.$time ); } if($corners>=11 && $corners<=11.99) {header('Location: http://maidenerleghweather.com/corners2.php?var1=' . $corners. '&var2='.$time ); } } ?> Code is not tested! It should, if i remember right, only redirect you if the submit button has been activated, and extra secure by setting a ?post in the URL. Quote Link to comment https://forums.phpfreaks.com/topic/268149-header-form-then-redirect-fails/#findComment-1376345 Share on other sites More sharing options...
Pikachu2000 Posted September 8, 2012 Share Posted September 8, 2012 Make sure error reporting is turned on, then when you see the error you're getting, read the sticky topic in this forum titled, "HEADER ERRORS - READ HERE BEFORE POSTING THEM". Quote Link to comment https://forums.phpfreaks.com/topic/268149-header-form-then-redirect-fails/#findComment-1376349 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.