Jump to content

Form Problem


ojsimon

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.