Site Search Store Search Term

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 4, 2013   (RSS)

Hi Craig,

I've created a very simple search term save system that you could base your system on. First I created a section called searches, I've attached an image that shows the fields that I added to it. 

Next I created a simple search form based on the one you are using in the post above. Then I created a PHP if statement that detects if someone has carried out a search and stores their search term in the searches section:

<?php
//If someone has carried out a search 
 if(@$_REQUEST['saveSearch'] && @$_REQUEST['search_terms']){
//Create an array of data to be saved, and validate it.    
$saveFields = array(
      'createdDate' => date('Y-m-d H:i:s'),
      'title'       => mysql_escape($_REQUEST['search_terms'])
    );
    //Add the  terms to the searches section
    mysql_insert('searches',$saveFields);
  }

?>

  <form method="get" action="scratch.php">
    <input type="hidden" name="saveSearch" value="true" />
    <input type="text" value="<?php echo @$_REQUEST['search_terms']; ?>"  name="search_terms" />
    <input type="submit" name="submit" value="Submit" />
  </form>

So if someone has carried out a search, and there is data in the search_terms search box, then it gets saved to the searches section. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com
Attachments:

searches.png 3K

By KCMedia - February 4, 2013

Hi Greg

perfect thank you very much works great.

Thanks



Craig

KC Media Solutions

www.kcmedia.biz