Page 1 of 1

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

Posted: Sat Mar 28, 2009 1:21 pm
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;

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

Posted: Sat Mar 28, 2009 2:22 pm
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

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

Posted: Sat Mar 28, 2009 2:26 pm
by phpnitemare
Thats brilliant, worked a treat, thank you :)