Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to search mysql using $ with " ' " 1

Status
Not open for further replies.

bccamp

Technical User
Jan 20, 2005
69
My code passes a variable through the url and is decoded on the page. The problem is 2 of the variables have " ' ". EX. Women's. When I go to search the db, I get mysql_num_rows() not valid: supplied argument is not a valid MySQL result...

Is there a way, without changing the data in the database, to make MySQL see Women's as Women%27s while allowing all other strings without this problem to work?

Or is there a better way entirely that I'm not seeing to get:
$query="SELECT * FROM db WHERE CATEGORY = '$string'";
$result=mysql_query($query);
$num=mysql_num_rows($result);

to work if $string is either Women's or Men & Women in the db?
 
rather than an ereg_replace i would suggest str_replace() function.

ereg uses regular expressions.

also have a look at addslashes() function...

Known is handfull, Unknown is worldfull
 
Thanks for both answers. I got the script to work with the ereg_replace expression. Worked great on my testing server with a newer MySql program. Didn't work when I uploaded to my server on Yahoo! MySql on Yahoo! did not need the conversion, whereas my newer version on my test server did. Unbelievable! Special scripts to test the program, remove special scripts to host the program...

Thanks again, and I'll check out the str_replace function for future use.

Barry
 
just check if u have magic_qoutes "on" locally, if that is on then this problem will never arise...

Known is handfull, Unknown is worldfull
 
Thanks vbkris,

I altered php.ini to magic_quotes = on and that resulted in:

men's to men"s in my category listing and
men""s when passed through the urlencode.

I think I broke it. ;)

Barry
 
no problemmo...

Known is handfull, Unknown is worldfull
 
Thanks again for all the help. As you can tell, I'm very new to this and this forum has solved hours of head banging against the desk problems. Learning php from scratch with books is like going to college with no professors. Thankfully there are many professors in this forum like you guys, otherwise this would be a miserable undertaking.

Thanks again for everything.

Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top