Hi trouble with str_replace and search query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Hi trouble with str_replace and search query

Post by sanju »

Hi all,

I am doing a search functionality.I need to get data entered with ', 5 etc..
So after entering data in search filed

The keyword is converetd to

Code: Select all

  $variable=str_replace("'","%\'",$variable);
[ /code] 
    Then  quotes problem is solved   then I need %  to work

  Now when entering % all fields are displaying   . how I should remove that..

     Regrads
Last edited by sanju on Mon Mar 16, 2009 7:12 am, edited 1 time in total.
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: Hi trouble with str_replace and search query

Post by mickeyunderscore »

Could you try and explain a bit better? Maybe show me some code or your database query?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Hi trouble with str_replace and search query

Post by Benjamin »

% is a mysql wild card in LIKE queries. That will display all records.
User avatar
sanju
Forum Commoner
Posts: 65
Joined: Sat Jun 21, 2008 2:15 am
Location: Kochi, India

Re: Hi trouble with str_replace and search query

Post by sanju »

Use javascript to remove % is that better or any other methods in PHP?
mickeyunderscore
Forum Contributor
Posts: 129
Joined: Sat Jan 31, 2009 9:00 am
Location: UK

Re: Hi trouble with str_replace and search query

Post by mickeyunderscore »

No, if you want to properly validate user input use PHP. JavaScript can be disabled.
Post Reply