954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Double quotes prob in mysql query

Hi frnds...

here i m doing search for my website...

$mcat='abc';

$query="SELECT * FROM news WHERE topic LIKE '%$mcat%' ";

here , the problem is in my db table $mcat value stored as doublequotes ...the word itself having double qoutes....

the above query working for all other sarch items, except double quotes words...plz give me some suggestions...

Thanks in advance...
Saritha...

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

use mysql_real_escape_string()

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 

you can use escape character

i/'ll 
something like this will work
kaion
Light Poster
36 posts since Apr 2009
Reputation Points: 13
Solved Threads: 8
 

you can even change the table to one without a quotation mark. hope it helps.shalom shalom

kaion
Light Poster
36 posts since Apr 2009
Reputation Points: 13
Solved Threads: 8
 
$mcat = mysql_real_escape_string($mcat);
$query="SELECT * FROM news WHERE topic LIKE '%$mcat%' ";
network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 

using addslash() is also a easy choice

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 
$mcat = mysql_real_escape_string($mcat);
$query="SELECT * FROM news WHERE topic LIKE '%$mcat%' ";


Hi ...

I already test mysql_real_escape_string($mcat)...but not working...
In my db th first letter if having "...
eg:

"hi" welcome...


but $mcat= 'hi';

it doesnt search...

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

sorry i don't agree with it, if the search string is 'hi' like $var = 'hi' and in your db there are below entries -
1.high
2.hi
3."hi!
4."hi"

all these will come in the query's result if done with -
mysql_query("select * from tbl where fieldName like '%".$var."' ");

network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
 

sorry i don't agree with it, if the search string is 'hi' like $var = 'hi' and in your db there are below entries - 1.high 2.hi 3."hi! 4."hi"

all these will come in the query's result if done with - mysql_query("select * from tbl where fieldName like '%".$var."' ");


Hi Network...i got it...

Thanks...i mis used ur suggestion...

now ok..its working...
Thanks once again...

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You