Zen Cart Logo
Forums / Bug Reports / Problems with apostrophes in my product search.

Problems with apostrophes in my product search.

Locked

Views: 3,202

Results 1 to 18 of 18
This thread is locked. New replies are disabled.
2 Sep 2009, 1:15 PM
#1
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Problems with apostrophes in my product search.

When i type the full name of a product into the site search it seems to be fire a 1064 error:

it would appear this is because within the product name there is a ' which has subsequently knocked the mysql code. Any tips for fixing?

Andy.

EDIT

Version 1.3.8a

2 Sep 2009, 4:10 PM
#2
shrimp_gumbo_mmmhhh avatar

shrimp_gumbo_mmmhhh

Totally Zenned

Join Date:
Jun 2007
Location:
Texas, USA
Posts:
1,436
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Andy,

This does not happen on my 1.3.8a.... albeit I have modified my search a lot. What is the keyword you are typing in?

Shrimp

2 Sep 2009, 4:14 PM
#3
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

well the thing i typed in was the exact name of a product which happens to contain an '

e.g

that's amore

will break the query because it contains an apostraphy.

Andy.

2 Sep 2009, 8:11 PM
#4
shrimp_gumbo_mmmhhh avatar

shrimp_gumbo_mmmhhh

Totally Zenned

Join Date:
Jun 2007
Location:
Texas, USA
Posts:
1,436
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

will check on it

2 Sep 2009, 8:12 PM
#5
shrimp_gumbo_mmmhhh avatar

shrimp_gumbo_mmmhhh

Totally Zenned

Join Date:
Jun 2007
Location:
Texas, USA
Posts:
1,436
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Works on mine.... have you made any changes to your code?

3 Sep 2009, 9:21 AM
#6
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Hey Shrimp,

to the best of my knowledge nothing has been changed on this. Perhaps there was an update to 1.3.8a that i missed which corrected the problem ill have a look. Basicaly i either need to having somthing remove any invalid chars like ' etc. Or for these to be handled in a different way.

ill have alook see if there are any minor tweeks that may have been released.

Andy.

11 Sep 2009, 7:00 PM
#7
shrimp_gumbo_mmmhhh avatar

shrimp_gumbo_mmmhhh

Totally Zenned

Join Date:
Jun 2007
Location:
Texas, USA
Posts:
1,436
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Andy_GS:

Hey Shrimp,

to the best of my knowledge nothing has been changed on this. Perhaps there was an update to 1.3.8a that i missed which corrected the problem ill have a look. Basicaly i either need to having somthing remove any invalid chars like ' etc. Or for these to be handled in a different way.

ill have alook see if there are any minor tweeks that may have been released.

Andy.

Andy,

Checked a couple in the live showcase and they worked fine.... checked the one in this thread and it didn't work:

http://www.zen-cart.com/forum/showthread.php?t=136173

I'm supposing since none on the dev team have responded that they think something has been modified on your cart to cause this..... you can take the ' out of the keywords but then the searches will not pull back the items you want them to pull back.

Shrimp

14 Sep 2009, 4:26 PM
#8
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

I just checked that site from that thread, and typed this in:

a'dobe

and it came back with the exact same error i get.

I just check this one:
http://www.boxandsupply.com

and they seem to add a \ where ever there is an '.

im guessing some sorter:

$var("'","\'",$var);

needs to be put somewhere or somthing similar, but i can't quite see from the /includes/modules/pages/advanced_search_result/header_php.php where exactly it should go.

any ideas?

Andy.

15 Sep 2009, 4:04 AM
#9
afo avatar

afo

Totally Zenned

Join Date:
Aug 2004
Location:
New York City
Posts:
6,800
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

An apostrophe (or single quote) is a special character in php denoting the beginning or end of a string. Putting a \ in front of is "escapes" it - meaning it tells the php that the character shouldn't be intrepreted as the start/end of a string. This has nothing to do with Zen Cart. It's the way php works.

15 Sep 2009, 11:27 AM
#10
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Yeah i understand that '' are used within php and that is the reason its not working as stated above.

So somewhere in the code this tag must be used:

mysql_real_escape_string

does this go in:
/includes/modules/pages/advanced_search/header_php.php

or

/includes/modules/pages/advanced_search_result/header_php.php

and if so where abouts?

kind regards

Andy.

23 Nov 2009, 11:09 AM
#11
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Hey all,

i was just updating this hoping that it might fix my other issue with the zen-cart search which was to escape any invalid characters within the search e.g.

using:
addslashes($str);

to prevent things like a search for O'reily where the apostraphe needs to have slashes applied to it.

Is there a way i can add this to the update?

also is this piece of code not supposed to have a php close at the end?

regards
Andy.

23 Nov 2009, 6:55 PM
#12
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: Problems with apostrophes in my product search.

Andy_GS:

also is this piece of code not supposed to have a php close at the end?
No.
Ref: https://www.zen-cart.com/tutorials/index.php?article=313

24 Nov 2009, 9:44 AM
#13
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Hi doc,
thats interesting to know,
many thanks
Andy.

16 Dec 2009, 6:50 PM
#14
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Hmm, no one still has come back to me with a definitive answer. If other peoples search escapes the use of a single apostraphe then could they share where and in what file this is done, because im struggling here to find the correct place to stop this from happening.

thanks in advance.

Andy.

17 Dec 2009, 8:46 AM
#16
kuroi avatar

kuroi

Totally Zenned

Join Date:
Apr 2006
Location:
London, UK
Posts:
10,475
Plugin Contributions:
11

Re: Problems with apostrophes in my product search.

Andy_GS:

Hmm, no one still has come back to me with a definitive answer. If other peoples search escapes the use of a single apostraphe then could they share where and in what file this is done, because im struggling here to find the correct place to stop this from happening.

thanks in advance.

Andy.Zen Cart does it's best to add the slashes when preparing the input for the database (and is successful on every site that I've tested this morning). You'll find this done in the query factory class (lines 54-62). But as you'll also see, this is dependent upon you using a version of PHP that includes the escaping functions, and your web host not having disabled them.

17 Dec 2009, 9:46 AM
#17
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

Hey guys,

@hugo13 - yep that does seem to work

@kuroi - I was starting to believe myself that this was the file i needed to change.
What i have done is this:

Lines 364 - 369

  case 'regexp':
        $searchArray = array('[', ']', '(', ')', '{', '}', '|', '*', '?', '.', '$', '^');
        foreach ($searchArray as $searchTerm) {
          $value = str_replace($searchTerm, '\\' . $searchTerm, $value);
        }
        return $this->prepare_input($value);

i changed the last line to this:

return addslashes($value);

which pretty much makes the above search array redundant. but for all those experiencing my problem this seem to fix it for me.

so the final bit displays as:

  case 'regexp':
        $searchArray = array('[', ']', '(', ')', '{', '}', '|', '*', '?', '.', '$', '^');
        foreach ($searchArray as $searchTerm) {
          $value = str_replace($searchTerm, '\\' . $searchTerm, $value);
        }
        return addslashes($value);

Enjoy
Andy.

17 Dec 2009, 9:56 AM
#18
andy_gs avatar

andy_gs

Zen Follower

Join Date:
Jun 2008
Posts:
187
Plugin Contributions:
0

Re: Problems with apostrophes in my product search.

ok i don't know what happened but i changed it and was convinced i had it working....... yeah its not lol :oops::(