Forum Moderators: coopster
My problem is this. I want a code, that would allow the phrase that i type in my html/php form, to be automatically put into a link in a search engine. I know how to do this with frames using variables, but how could i do that with opening new pages?
How I would like it to go:
www.mypage.com/search contains a webform. I input a phrase like BOB in the webform, and it transfers me to a link like [google.com ]
All i need is the corect syntax how to input that there...
all you owuld need to do is grab the value from your $_POST array, concatenate it into your string (url) and then feed that string to the header function.
if your textbox was call 'searchterm' then it might look something like
$st = $_POST['searchterm'];
$url = 'http://www.google.com/search?hl=en&q=' . $st . '&btnG=Google+Search';
header("Location: $url");
this would send them off to google with the required url. I did not add any data verification to the first line which you should add but you can test this to see if it does what you want.
Fix my code/Do My Homework posts are not all that welcome. This is a discussion board, if you have a problem, try to phrase your post in a manner condusive to discussion of the issue. We want to teach people to help themselves. (Give a man a fish, and you feed him for a day. Teach a man to fish, you feed him for a life time.
save the above code to a file with whatever name you like, let's call it redir.php
then you make a form and add that script name to the form action. For this example the files need to be in the same directory. Something like this would be fine
<form name="getsearchterm" method="post" action="redir.php">
<br>enter your search term: <input type="text" name="searchterm">
<br><input type="submit" value="Search for it">
</form>
give that a shot
And welcome to WebmasterWorld!