grk101 Posted June 2, 2009 Share Posted June 2, 2009 how can i do this .. in my html I have a search box and a drop down menu. in my drop down i have three choices. So you can search the main site, the sister site or others <form id="form1" name="form1" method="post" action="post.php"> <label>search <input type="text" name="search" id="search" /> <select name=""> <option value="main">main site</option> <option value="sister">sister site</option> <option value="other">other site</option> </select> </form> </body> Really, i just want a PHP code that will take the search term and redirect them to the proper page So ,, IF "main" is selected from the drop down, redirect them to the main site passing the search variable so maybe like this? $search = ($_POST['search']); $main = ($_POST['main']); if ($main header location(main.php?$search') else echo "Make a selection!"; Can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/ Share on other sites More sharing options...
Ken2k7 Posted June 2, 2009 Share Posted June 2, 2009 PHP 101. Read up on that. You're messing up the if statement and the header. Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-847496 Share on other sites More sharing options...
grk101 Posted June 2, 2009 Author Share Posted June 2, 2009 <?php $search = ($_POST['search']); $san = ($_POST['san']); if ($san) { header( "Location: http://yahoo.com" ); } else echo "Have a nice day!"; ?> so i got that working, what i can't figure out is how do i pass each individual value from the <option select > because the <select name = "san"> it's only passing the "san" instead of the drop down choices. i have given them values any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-847502 Share on other sites More sharing options...
BK87 Posted June 2, 2009 Share Posted June 2, 2009 should work just fine... try seeing what "san" is posting... print_r($_POST["san"]); Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-847506 Share on other sites More sharing options...
grk101 Posted June 2, 2009 Author Share Posted June 2, 2009 <form id="form1" name="form1" method="post" action="post.php"> <label>search <input type="text" name="search" id="search" /> <select name="san"> <option value="main">main site</option> <option value="sister">sister site</option> <option value="other">other site</option> </select> </form> </body> the San is not passing any values of the drop down not sure why? would i have to do the follwoing for each? $main = ($_POST['main']); Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-847510 Share on other sites More sharing options...
BK87 Posted June 2, 2009 Share Posted June 2, 2009 I just tried your from it works fine here.. try it out... <? if($_POST["san"]){ echo "You selected ".$_POST["san"]; } ?> <form id="form1" name="form1" method="post" action=""> <label>search <input type="text" name="search" id="search" /> <select name="san"> <option value="main">main site</option> <option value="sister">sister site</option> <option value="other">other site</option> </select> </form> </body> Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-847517 Share on other sites More sharing options...
grk101 Posted June 2, 2009 Author Share Posted June 2, 2009 thanks BK87 , that helped! question if i use header location to redirect to the search page in the redirection url lets say http://www.yahoo.com can i use the following: http://www.yahoo.com/$search Basically can i add the variable $search in the location header or do i have to use special quotes etc? Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-847545 Share on other sites More sharing options...
dreamwest Posted June 2, 2009 Share Posted June 2, 2009 thanks BK87 , that helped! question if i use header location to redirect to the search page in the redirection url lets say http://www.yahoo.com can i use the following: http://www.yahoo.com/$search Basically can i add the variable $search in the location header or do i have to use special quotes etc? No quotes needed in header if theres already double quotes header("Location: yahoo.com/$search/title/$page"); Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-847551 Share on other sites More sharing options...
grk101 Posted June 2, 2009 Author Share Posted June 2, 2009 how many if statements like these can i use? if ($san) header( "Location: http://yahoo.com" ); exit; if ($san) header( "Location: http://google.com" ); exit; I have four different URLS' but only the first IF statement works. how can i get the others to work and redirect? Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-848032 Share on other sites More sharing options...
Vince889 Posted June 2, 2009 Share Posted June 2, 2009 The second won't work because the first one already directed the user to yahoo.com. You need some conditions. Example: <? if ($san == "Dog") { // If the variable 'san' equals 'Dog', then you'll go to Yahoo.com header("Location: http://yahoo.com"); } if ($san == "Cat") { // If the variable 'san' equals 'Cat', then you'll go to Google.com header("Location: http://google.com"); ?> In a way, you're confusing PHP. You have two identical IF statements that are BOTH possible, so it will just go with the first one by default. Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-848039 Share on other sites More sharing options...
grk101 Posted June 2, 2009 Author Share Posted June 2, 2009 is it wrong to use exit; after the header? thanks though everyone! this has worked out!! Quote Link to comment https://forums.phpfreaks.com/topic/160585-solved-simple-if-question-help-needed/#findComment-848048 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.