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 Link to comment https://forums.phpfreaks.com/topic/94342-form-problem/ Share on other sites More sharing options...
darkfreaks Posted March 4, 2008 Share Posted March 4, 2008 use htaccess mod_rewrite for the url Link to comment https://forums.phpfreaks.com/topic/94342-form-problem/#findComment-483133 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 Link to comment https://forums.phpfreaks.com/topic/94342-form-problem/#findComment-483136 Share on other sites More sharing options...
ojsimon Posted March 4, 2008 Author Share Posted March 4, 2008 Hi What are the limitations? thanks Link to comment https://forums.phpfreaks.com/topic/94342-form-problem/#findComment-483139 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 Link to comment https://forums.phpfreaks.com/topic/94342-form-problem/#findComment-483145 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 Link to comment https://forums.phpfreaks.com/topic/94342-form-problem/#findComment-483160 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.