Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Quick search always shows Invalid keywords error


syscon

Recommended Posts

Hello,

I have recently migrated my site to PHP 8 and while I have fixed most errors, I don't know PHP that well and am not seeing any errors pop up from PHP, just a possibly related warning shown below. I know it is not an issue with my database and the search worked when I was on PHP7. I see a deprecated function warning about strtolower() but I assume this is not the issue. I also see a warning like so: 
 

Undefined variable $search_keywords in /var/www/localhost/htdocs/site_name/catalog/advanced_search_result.php on line 109

Even when setting this variable to an empty string under the line where $keywords is defined, line 32, the warning disappears yet the problem is not solved. I have looked at multiple other forum posts from 2006 or 2010 but none of their solutions worked for me. I have attached as a dpaste link here what I believe to be the relevant file to this problem, advanced_search_result.php , please let me know if this is ok. I have tried printing the variable $search_keywords but it is also empty and I do not know where it is being set. 

Any help would be appreciated, thank you!

#Joseph

Link to comment
Share on other sites

2 hours ago, syscon said:

deprecated function warning about strtolower

That function should work in php 8 - see here. But all such warnings should be fixed since some will cause failures.

 

2 hours ago, syscon said:

line where $keywords is defined, line 32

This is not the location in all versions so you have to state yours in order to get help. But the variable should be declared after the include application_top statement to ensure there isn't a problem with its scope.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

On 9/25/2024 at 8:19 PM, Jack_mcs said:

This is not the location in all versions so you have to state yours in order to get help. But the variable should be declared after the include application_top statement to ensure there isn't a problem with its scope.

I have version 2.2, though in order to get help, I did include the code of the file, advanced_search_result.php, in the dpaste link I shared, were you able to see it? I figured pasting the entirety of the file into one code block would clutter the post. I did try declaring the variable as stated as well but again, no error, just that the declared variable was nothing but an empty string when echoed.

On 9/25/2024 at 8:19 PM, Jack_mcs said:

That function should work in php 8 - see here. But all such warnings should be fixed since some will cause failures

Apologies, it wasn't the function but rather passing null as a parameter was deprecated. I have fixed the warnings I saw however, still seeing the same error. 

The first part of the function tep_parse_search_string which is being used on $search_keywords looks like this: 

// Parse search string into indivual objects
  function tep_parse_search_string(&$objects, $search_str = '') {
    $search_str = trim(strtolower($search_str));

As far as I understand, the searchbar's input should be used in the variable $search_keywords which is then passed to the function tep_parse_search_string. However, the searchbar input is not being pulled into that variable. Is my file missing something?

 

Thank you

#Joseph

Link to comment
Share on other sites

Hi wheelshop, 

30 minutes ago, wheelshop said:

There are two calls to that function so you need to determine which it is and then determine which argument is causing the problem. I do suggest you replace all $HTTP_GET_VARS with $_GET since the former has be deprecated.

I have replaced that variable, thanks for letting me know. However, I am confused on your first part. By "that function" do you mean tep_parse_search_string? I have already determined which call and argument is causing the problem as mentioned in my previous replies. It is the call on line 109 of the file in my dpaste link: https://dpaste.org/qeJQX and the argument $search_keywords. The argument is empty rather than filled with the user's search input.

I am just not sure where in the code that happens, where $search_keywords is set to the user's input. 

#Joseph

Link to comment
Share on other sites

41 minutes ago, syscon said:

It is the call on line 109 of the file

Try adding the following before that line:

$search_keywords = null;

Or, change line 109 to

if (! empty($search_keywords) && !tep_parse_search_string($keywords, $search_keywords)) {

I have several shops running with php 8 and they don't require the above changes so I think the cause is due to something else. But one of the above changes might stop it.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

By changing $search_keywords to be null, it throws this:

Quote

Deprecated: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated

Which is what I was getting earlier before. 

However, with the second change of yours, it finally stops returning the invalid keyword error. But instead, it returns my entire stock rather than only the items relevant to the search. By having search_keywords be null, isn't that the same as pressing search with an empty search string so it returns everything? Since the default value of the search string being passed into tep_parse_search_string is an empty string which it uses since we are passing in null. I'm a little confused on how this works. 

#Joseph

Link to comment
Share on other sites

57 minutes ago, syscon said:

By having search_keywords be null, isn't that the same as pressing search with an empty search string so it returns everything?

You shouldn't be able to search on an empty string. If your code is allowing that, then it has been edited and may be part of the problem. The search_keywords being passed in the function is just a holder. A better change than what I mentioned previously would be to change the function like this

 function tep_parse_search_string($search_str = '', &$objects = []) {

The purpose of that function is to parse the searched for keywords into an array. The search_keywords passed in will be created and cleared so it doesn't matter what it contains when sent.

Are you searching for something that is specific that only exists in a product or two? Or are you searching for something that might be in all of them, like the letter "a"? The latter will return many results, most likely.

You have this part of the code removed that handles the created search_keywords. I don't know how that will affect this but you might want to try enabling that block of code. It's difficult troubleshooting code that has been altered like this since there is no way to know what other changes have been made. You may want to try installing a shop with clean files and get it to work with php 8 and then apply those changes to this shop.

         /*   case '(':
            case ')':
            case 'and':
            case 'or':
              $where_str .= " " . $search_keywords[$i] . " ";
              break; */

 

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

Yes I had disabled that block on code on the suggestion of someone else and re-enabled it now.  I am searching for something  specific that should only bring 5 or 6 results. I understand the code better now though thank you. I will try to undo any changes made that might have messed things up and take a look at working with some clean files. Thank you for the help!

#Joseph

Link to comment
Share on other sites

Does anybody have a "oscommerce-2.2rc2a" running on PHP-8?

If so can you post files:

advanced_search_result.php

includes/functions/general.php

I would like to compare them to my files.

Thank you!

 

#Joseph

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...