Search form doesn't work

9 posts by 2 authors in: Forums > CMS Builder
Last Post: September 30, 2020   (RSS)

By CommonSenseDesign - September 30, 2020 - edited: September 30, 2020

I have a search form on my site, which doesn't seem to be picking up some keywords. http://wilmotpost.ca/demo/index.php

Searching for the word "indigenous" doesn't show any results, even though there are clearly at least two articles that contain it. That's just one example, but there are others, too. Any idea what might be causing this, please?

<form action="search.php">
<div class="row no-gutters mt-3">
<div class="col">
<input type="text" name="title_keyword,content_keyword,main_article_keyword,author_keyword" value="">
<input type="submit" name="submit" value="Search">
</div>
</div>
</form>

Attachments:

_navbar.php 8K

index.php 11K

Search form doesn't work after first search

By Carl - September 30, 2020

Hi,
Do you have any examples of keywords that do work?  The keywords I tried didn't show any results. Can you share the search.php file? You should use a single word without any commas in your input name and you can use the value from that variable to query the database for any item in your database you wish to query.

Carl

PHP Programmer

interactivetools.com

Search form doesn't work after first search

By CommonSenseDesign - September 30, 2020

Hi, Carl.

For some reason, it seems to pick up my last name, as I wrote some of the articles, but it doesn't catch anything else!

http://wilmotpost.ca/demo/search.php?title_keyword%2Ccontent_keyword%2Cmain_article_keyword%2Cauthor_keyword=gordijk&submit=Search

I've attached the search results page.

Attachments:

search.php 8K

_navbar.php 8K

Search form doesn't work after first search

By Carl - September 30, 2020 - edited: September 30, 2020

Disclaimer: I haven't tested this yet.

<form action="search.php" method="post">
    <div class="row no-gutters mt-3">
        <div class="col">
            <input type="text" name="query">
            <input type="submit" name="submit" value="Search">
        </div>
    </div>
</form>

After that, on search.php I would change this:

  // load records from 'homepage_insets'
  list($homepage_insetsRecords, $homepage_insetsMetaData) = getRecords(array(
    'tableName'   => 'homepage_insets',
    'perPage'     => '10',
    'loadUploads' => true,
    'allowSearch' => true,
  ));

to something similar:

$query = @$_REQUEST['query']; // this will hold the keyword

  // load records from 'homepage_insets'
  list($homepage_insetsRecords, $homepage_insetsMetaData) = getRecords(array(
    'tableName'   => 'homepage_insets',
    'perPage'     => '10',
    'loadUploads' => true,
    'allowSearch' => true,
    'where'       => " title_keyword LIKE '%".mysql_escape($query)."%' ",
  ));


Let me know if that works.

Carl

PHP Programmer

interactivetools.com

Search form doesn't work after first search

By Carl - September 30, 2020

Yes, it would search only one field. If you know the names of the other fields, you can do something like

$query = @$_REQUEST['query']; // this will hold the keyword

  // load records from 'homepage_insets'
  list($homepage_insetsRecords, $homepage_insetsMetaData) = getRecords(array(
    'tableName'   => 'homepage_insets',
    'perPage'     => '10',
    'loadUploads' => true,
    'allowSearch' => true,
    'where'       => " title_keyword LIKE '%".mysql_escape($query)."%' OR content_keyword LIKE '%".mysql_escape($query)."%' ",
  ));

and you can add all the fields you want to search using that format.

Carl

PHP Programmer

interactivetools.com

Search form doesn't work after first search

By CommonSenseDesign - September 30, 2020

I'm afraid not; I'm getting this error message when I run a search:

MySQL Error: Unknown column 'title_keyword' in 'where clause'

http://wilmotpost.ca/demo/index.php

Attachments:

_navbar.php 8K

search.php 9K

Search form doesn't work after first search

By Carl - September 30, 2020

Try this

$query = @$_REQUEST['query']; // this will hold the keyword

  // load records from 'homepage_insets'
  list($homepage_insetsRecords, $homepage_insetsMetaData) = getRecords(array(
    'tableName'   => 'homepage_insets',
    'perPage'     => '10',
    'loadUploads' => true,
    'allowSearch' => true,
    'where'       => " title LIKE '%".mysql_escape($query)."%' OR content LIKE '%".mysql_escape($query)."%' ",
  ));
Carl

PHP Programmer

interactivetools.com

Search form doesn't work after first search

By CommonSenseDesign - September 30, 2020

Perfect! Thank you so much.