Page 1 of 1

Make your own text box link to Google in php

Posted: Sun Mar 26, 2006 10:08 pm
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!

Posted: Mon Apr 17, 2006 4:04 am
by mohumben
Oh my, why all this?

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

Think simple ;)

Posted: Thu Jun 01, 2006 11:16 pm
by redwall_hp
Hehe. That's right think simple! Or I suppose Platinum could argue "Think Different"....

Posted: Sun Jul 23, 2006 10:58 pm
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>

Posted: Mon Jul 24, 2006 1:38 am
by jeremy90
thanks for the code even if you did just edit the one on google adsense

Posted: Sat Jul 29, 2006 3:30 pm
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.