Skip to main content
October 5, 2012
Question

Trouble with the & in a querry

  • October 5, 2012
  • 1 reply
  • 961 views

Simple querry but when I do this statement:

SELECT NAME, KEYWORDS, `DESCRIPTION`, SKU, MANUFACTURER, PRICE, RETAILPRICE, BUYURL, IMPRESSIONURL, IMAGEURL, ADVERTISERCATEGORY

FROM Cruiser

WHERE ADVERTISERCATEGORY LIKE '%License Plate Frames & Relocation%'

ORDER BY NAME ASC

MySQL Error 1064

You have anerror in your SQL syntax; near "%License Plate Frames' at line 1

Any help would be great

This topic has been closed for replies.

1 reply

Participating Frequently
October 5, 2012

Assuming you are using PHP - In PHP the ampersand is a special character so you need to deal with that. I don't know PHP but you could try escaping the ampersand with a backslash : WHERE ADVERTISERCATEGORY LIKE '%License Plate Frames \& Relocation%' or try using htmlentities()

David_Powers
Inspiring
October 6, 2012

The ampersand has nothing to do with the error message. Although the ampersand occasionally has a special meaning in PHP, it doesn't need escaping in a string.

The error message comes from MySQL, which always identifies a SQL error as being "near" something. What that means is that the error immediately precedes whatever follows "near". In this case, the error is "near" %License Plate Frames. In other words, the opening single quote is creating the problem. It would appear there's a problem with matching quotes in the string that passes the SQL query to the database.

Participating Frequently
October 7, 2012

You might want to post the entire code from the page. This sql SELECT is different the one you originally posted in this thread: http://forums.adobe.com/message/4752558#4752558