Make your own text box link to Google in php

Any problem with PHP can be disscused here
Post Reply
znad
Posts: 250
Joined: Sat Oct 01, 2005 3:12 pm

Make your own text box link to Google in php

Post by znad »

In this tutorial I will show you how to create a text box so that when you **** search it will search Google.

Fist start off in you php file then add your form in php


PHP Code:
<?
echo '<form name="form1" method="post" action="';
echo /decadecreations/tutorialarea.php;
echo '">
<input type="text" name="search">
<input type="submit" name="Submit" value="Search">
</form>';
}
?>



That will be the forum part of your script.

Notice how the submit action is /decadecreations/tutorialarea.php this is so that it will submit to it self.

Now add this script ABOVE the one you just put, this is were it will connect what you have typed to Google.

<?php
if($_POST){
$searchtext = $_POST['search'];

echo '<p align="center"><meta http-equiv="Refresh" content="1;URL=http://www.google.ca/search?hl=en&q=';
echo ;
echo '&btnG=Google+Search&meta=">';
echo 'CONNECTING TO GOOGLE...';
}
else
{
// do anything
}
?>
Now lets learn a little about this part of the script.

First I have the if($_post) part of the script, this means when a page submits to it, it will not show the forum it will just show what you put there, this is why we put in $PHP_SELF.

The echo part is just some basic HTML coding so that it will refresh and go to that page, as you can see a broke the HTML up so that I could add in the part so that it gets $searchtext.

the $searchtext variable gets what you have typed by another simple php script which is $_POST['search'] that script will look for the text field called search and as you can see we have one called that and that is the one that you put in your text that you want to search.

Then under all of that a just have an echo that says connecting to google.

Here is how the final script should look once it is all put together:
<?php
if($_POST){
$searchtext = $_POST['search'];

echo '<p align="center"><meta http-equiv="Refresh" content="1;URL=http://www.google.ca/search?hl=en&q=';
echo ;
echo '&btnG=Google+Search&meta=">';
echo 'CONNECTING TO GOOGLE...';
}
else
{
echo '<form name="form1" method="post" action="';
echo /decadecreations/tutorialarea.php;
echo '">
<input type="text" name="search">
<input type="submit" name="Submit" value="Search">
</form>';
}
?>
Moderated by Lixas: for PHP code use QUOTE tags!


mohumben
Posts: 82
Joined: Thu Sep 15, 2005 9:45 pm

Post by mohumben »

Oh my, why all this?

http://www.google.com/searchcode.html

Think simple ;)

Code: Select all

define('I_LOVE_PHP', true);
redwall_hp
Posts: 24
Joined: Thu Jun 01, 2006 3:22 pm

Post by redwall_hp »

Hehe. That's right think simple! Or I suppose Platinum could argue "Think Different"....
mohumben
Posts: 82
Joined: Thu Sep 15, 2005 9:45 pm

Post by mohumben »

Think even more simple:

Code: Select all

<form action="http://www.google.com/search" method="get">
<input type="text" name="q">
<input type="submit" value="Search">
</form>

Code: Select all

define('I_LOVE_PHP', true);
jeremy90
Posts: 440
Joined: Mon Jun 26, 2006 3:15 pm

Post by jeremy90 »

thanks for the code even if you did just edit the one on google adsense
barnes
Posts: 202
Joined: Tue May 16, 2006 5:09 am

Post by barnes »

jeremy90 wrote:thanks for the code even if you did just edit the one on google adsense
And adsenses searc searches your site too.
Post Reply