0

Okay im not sure what this would be called im sure there is a word for it but the basic's are I want the php script to make a search bar on my homepage but the thing is I already have a search bar in place.

So all I really want is for the php bar to direct the user to a different url based on what they enter so obviously the spaces will become + signs.

The format would be:

www.Mysite.com/videos/search_result.php?query=FIRSTWORD+SECONDWORD&type=videos&submit=Search

So to break this down it would enter this:

www.Mysite.com/videos/search_result.php?query=

Then the first word then a space then the second word and continue this pattern for however many words there are and then:

&type=videos&submit=Search

Im sure there is a better way to explain this but I know basically nothing about PHP and I was hoping you could help thank you a ton btw.

noetix
  • 4,773
  • 3
  • 26
  • 47
Bishop Morley
  • 193
  • 1
  • 2
  • 8

2 Answers2

0

in the php code you get it by:

$query = $_POST['query']; //if your search bar form is post of course, otherwise $_GET

header("Location: /search_result.php?query=$query&type=videos&submit=Search");
0

To do this in HTML using a form:

<form action="/search_result.php" method="GET">
    <input type="text" name="query" />
    <input type="hidden" name="type" value="videos" />
    <input type="hidden" name="submit" value="Search" />
    <input type="submit" value="Search" />
</form>

If you need to URL encode a "search query" using PHP, see urlencode.

noetix
  • 4,773
  • 3
  • 26
  • 47
  • that is so close to what I need the only thing I need is that after my url it adds the extension videos Right now its just putting the url and then the text typed but it needs to put the url then /videos then the search how could I do this – Bishop Morley Oct 22 '12 at 03:06
  • If the parameter order is important (it shouldn't be), you would need to use JavaScript to piece together the new URL, again using URL encoding. See [How to encode a URL in Javascript?](http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript) for reference. – noetix Oct 22 '12 at 03:09