Jump to content

Headers W/ Forms


hansman

Recommended Posts

i would like to make a search page in which i can search google, and yahoo. The user may specify what site they with to use by a drop down menu, how can i code the page so that the options in teh drop down menu will use the right header..?

and can i put more then one header on a page..


thanks in advance
Link to comment
Share on other sites

Why not have something like this...

HTML Page (Not sure the syntax is exact):
[code]
<form name="search" method="GET" action="search.php">
<select name="engine">
  <option name="google">Google.com</option>
  <option name="yahoo">Yahoo.com</option>
</select>
<input type="text" name="string">
</form>
[/code]

This calls search.php which looks like this
[code]
<?php
  $engine = urlencode($_GET['engine']);
  $string = urlencode($_GET['string']);

  if ($engine == "google"){
      $url = "http://www.google.com/search?q=$string";
  }
  elseif ($engine == "yahoo"){
      $url = "http://search.yahoo.com/search?p=$string";
  }

  header("Location: $url");
?>[/code]

Should work a treat.

Regards
Rich
Link to comment
Share on other sites

My bad... I put the wrong values in the php if condition

[code]
<?php
  $engine = urlencode($_GET['engine']);
  $string = urlencode($_GET['string']);

  if ($engine == "Google.com"){
      $url = "http://www.google.com/search?q=$string";
  }
  elseif ($engine == "Yahoo.com"){
      $url = "http://search.yahoo.com/search?p=$string";
  }

  header("Location: $url");
?>
[/code]

Regards
Rich
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.