Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2018
    Location
    USA
    Posts
    11
    Plugin Contributions
    0

    Default MySQL custom fulltext search results breaking when ' or " are entered in search

    [Note: remember to include site URL, ZC version, list of plugins, PHP version, etc ... read the Posting Tips shown above for information to include in your post here. And, remove this comment before actually posting!]

    Website is http://beyondherbs.com. PHP 5.6. ZC 1.55 f. Alto theme.

    I modified the advanced search results header.php as mentioned here (https://www.zen-cart.com/showthread....arch-results#6) which has successfully improved my search results by way of utilizing the MySQL built in full text searching capabilities. The change is quite preferred to the default search results.

    However, because this modification utilizes MySQL, it is not allowing searches that use an apostrophe or quotation mark. This is problematic, and can be confusing to customers.

    Is it possible to add a line of code to /includes/modules/pages/advanced_search_result/header.php that will remove or format the " or ', so that the search may work, even when these characters are entered? I found two suggestions, but am unsure where they go.

    Suggestion 1 recommends using sanitize_text_field: https://wordpress.stackexchange.com/...ith-apostrophe

    Suggestion 2 recommends using a line to replace the ' or " with a /, so that the code will be removed. I am unsure if this would work while maintaining search integrity, but I am down to give it a shot.

    -

    Thank you for your assistance, ZC team and community!

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: MySQL custom fulltext search results breaking when ' or " are entered in search

    The wordpress suggestion would be pointless.

    I haven't tested this, but the following might work, and will be a lot more secure:
    Replace:
    Code:
    $from_str = ",  MATCH(pd.products_name) AGAINST('$robs_keywords') AS rank1, MATCH(pd.products_description) AGAINST('$robs_keywords') AS rank2 ";
    with
    Code:
    $from_str = ",  MATCH(pd.products_name) AGAINST(:robskeywords) AS rank1, MATCH(pd.products_description) AGAINST(:robskeywords) AS rank2 ";
    $from_str = $db->bindVars($from_str, ':robskeywords', $robs_keywords, 'string');
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Apr 2018
    Location
    USA
    Posts
    11
    Plugin Contributions
    0

    Default Re: MySQL custom fulltext search results breaking when ' or " are entered in search

    Thank you DrByte, I will test this tomorrow and report back my findings.

  4. #4
    Join Date
    Apr 2018
    Location
    USA
    Posts
    11
    Plugin Contributions
    0

    Default Re: MySQL custom fulltext search results breaking when ' or " are entered in search

    It worked! Maybe these modifications would make a good addition to a future release? Either way, this is exactly what I was looking for. Thanks! Going to buy the Zen team some coffee now :)

 

 

Similar Threads

  1. Custom Search or Manufacturer Results Page
    By joew36 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 20 Mar 2012, 09:25 PM
  2. Custom Page with search results
    By tini1709 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 4 Nov 2010, 10:45 AM
  3. Custom search results pages
    By mediathing in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 5 Dec 2007, 08:01 PM
  4. custom search results
    By saikii in forum General Questions
    Replies: 0
    Last Post: 8 Jun 2007, 02:14 AM
  5. Replies: 8
    Last Post: 5 Dec 2006, 10:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR