zwkle Posted February 6, 2009 Share Posted February 6, 2009 Hi, I have a search box on my site. Currently I have used the POST method, but I want to be able to have links on my site that execute searches when clicked, so I think I need to use the GET method. I have created the following test pages to explain my problem: First I have the search box (using the POST method): <form action='search.php' method='post'> <input type="text" name="searchstring" size="50"> <input type="submit" value="Search"> And then I have the file search.php <?php $searchstring=$_POST['searchstring']; echo $searchstring; ?> This outputs the searched for string as expected. Now, if I substitute POST for GET, first creating the page: <form action='search.php' method='get'> <input type="text" name="searchstring" size="50"? <input type="submit" value="Search"> and changing the file search.php to <?php $searchstring=$_GET['searchstring']; echo $searchstring; ?> I find that the searched for string isn't outputted. Can anyone tell me what is wrong? Basically my issue is that I don't know how to obtain the searchstring and use it in my code when I'm using the GET method. Many thanks, Andrew Quote Link to comment https://forums.phpfreaks.com/topic/144089-solved-difficulty-using-get_method/ Share on other sites More sharing options...
Mark Baker Posted February 6, 2009 Share Posted February 6, 2009 It should work, Are you doing any checking against the submit button at all? but you could always try resetting the form to use post, and then use $searchstring=$_REQUEST['searchstring'] in your code. That should allow both post and get methods to send to the search.php script Quote Link to comment https://forums.phpfreaks.com/topic/144089-solved-difficulty-using-get_method/#findComment-756018 Share on other sites More sharing options...
Maq Posted February 6, 2009 Share Posted February 6, 2009 If you use the GET method than the links are going to be preset. $_GET is used for variables in the URL. You would do something like this for GET: Page with link: $search_string = "underwear"; search underwear search.php $searchstring=$_GET['searchstring']; echo $searchstring; ?> Quote Link to comment https://forums.phpfreaks.com/topic/144089-solved-difficulty-using-get_method/#findComment-756022 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.