Make your own text box link to Google in php
Posted: Sun Mar 26, 2006 10:08 pm
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:
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.
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:
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.
Now lets learn a little about this part of the script.<?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
}
?>
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:
Moderated by Lixas: for PHP code use QUOTE tags!<?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>';
}
?>