ojsimon Posted March 4, 2008 Share Posted March 4, 2008 Hi I am making a search form that returns the word that the user searched as an experiment, this is the code i am using on index.html <html> <body> <center><form action="welcome.php" method="post"> <input type="text" size="40" name="name" /></center> <center><input type="submit" value="Search" /></center> </form> </html> Then for the second page welcome.php i am using <?php echo $_POST["name"]; ?> What i want is firstly for what the user searches to be in the url for example in a google search for php http://www.google.co.uk/search?hl=en&q=php&btnG=Google+Search&meta= php is in the url how can i make mine so it is /search?PHP for example? Also how can i make it so on the second page the search box is there? Thanks Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 4, 2008 Share Posted March 4, 2008 use htaccess mod_rewrite for the url Quote Link to comment Share on other sites More sharing options...
craygo Posted March 4, 2008 Share Posted March 4, 2008 if you use GET instead of POST the form fields will show up in the url <form action="welcome.php" method="GET"> so with the form above you will see www.yourdomain.com/welcome.php?name=xxxxxx Then you will have to use $_GET instead of $_POST. There are limitations to using the GET option. Ray Quote Link to comment Share on other sites More sharing options...
ojsimon Posted March 4, 2008 Author Share Posted March 4, 2008 Hi What are the limitations? thanks Quote Link to comment Share on other sites More sharing options...
ojsimon Posted March 4, 2008 Author Share Posted March 4, 2008 Hi How do i make it so that there is a search box on the welcome.php page too? thanks the get works perfectly thanks Quote Link to comment Share on other sites More sharing options...
craygo Posted March 4, 2008 Share Posted March 4, 2008 you don't have to call another page everytime you have a form. You can use 2 different ways to keep things all on the same page. <?php // using action=\"$_SERVER['PHP_SELF']\" will reload the same page with the variables // You can also use action=\"\" echo "<center><form action=\"$_SERVER['PHP_SELF']\" method=\"GET\" />\n"; echo "<input type=\"text\" size=\"40\" name=\"name\" /></center>\n"; echo "<center><input type=\"submit\" name=\"submit\" value=\"Search\" /></form></center>\n"; if(isset($_GET['submit'])){ // run the query here for the search } ?> Ray Quote Link to comment 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.