Help taking a string value from a search box to check result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpnitemare
Forum Newbie
Posts: 12
Joined: Sat Mar 28, 2009 1:14 pm

Help taking a string value from a search box to check result

Post by phpnitemare »

Hello,

I am currently learning php, I have a header.php which contains the search box see below

Code: Select all

 "<form method='post' action='search.php'> \n".
             "<td align='right'><input type='text' size='20' name='search'> <input type ='submit' value='Search'></td> \n".
             "</form></tr> \n".
 
On the search.php i need to get the input from the search box and assign this to $var
Currently I was assuming the value 'search' from the first code would contain the search string and therefore assign to the $var although this is not working, any help would be appreciated

Code: Select all

// Get the search variable from URL
  $var = Search;
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: Help taking a string value from a search box to check result

Post by tech603 »

On the page you are posting to "search.php" you would set the posted variable. To get the posted variable you would do
$_POST['search']

This tutorial should also help you on the rest of your way.
http://www.w3schools.com/php/php_forms.asp

hope that helps
phpnitemare
Forum Newbie
Posts: 12
Joined: Sat Mar 28, 2009 1:14 pm

Re: Help taking a string value from a search box to check result

Post by phpnitemare »

Thats brilliant, worked a treat, thank you :)
Post Reply