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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.