Forum Moderators: open

Message Too Old, No Replies

Problem with " & " vs "&"

         

bumpaw

2:59 pm on Sep 20, 2006 (gmt 0)

10+ Year Member



Using PHP 4 and MySQL 5 I have this Query:
[3]$Asql ="SELECT Distinct $subcat FROM feed WHERE $catlast LIKE '%".$hyphen."%' ORDER BY $subcat";[/3]

This is a datafeed implementation and looks for all the distinct category or subcategory names to create links for them. The trouble is with certain category values like "Pots & Pans". This type of value is not matched, but if the value is edited in the database to "Pots&Pans" the Query will pick it up.

spinnercee

2:31 pm on Sep 21, 2006 (gmt 0)

10+ Year Member



Try mysql_real_escape_string() on the query variables before sending the query.

$Asql ="SELECT Distinct " . mysql_real_escape_string($subcat) . " FROM feed WHERE " . mysql_real_escape_string($catlast) . " LIKE '%". mysql_real_escape_string($hyphen) ."%' ORDER BY " . mysql_real_escape_string($subcat) . "";

It's most important for the WHERE and LIKE clauses, but it's a good idea overall because of the special symbol differences between PHP and MySQL.

bumpaw

9:19 pm on Sep 22, 2006 (gmt 0)

10+ Year Member



Try mysql_real_escape_string()
I'll give that a try spinner. Thanks

bumpaw

6:30 pm on Oct 10, 2006 (gmt 0)

10+ Year Member



From The Manual:
mysql_real_escape_string() calls MySQL's library function mysql_real_escape_string, which prepends backslashes to the following characters: \x00, \n, \r, \, ', " and \x1a

This doesn't seem to have any effect on '&'.