Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trouble with the & in a querry

Guest
Oct 05, 2012 Oct 05, 2012

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

TOPICS
Server side applications
964
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 05, 2012 Oct 05, 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()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 06, 2012 Oct 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2012 Oct 07, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 07, 2012 Oct 07, 2012

That is the code. When I dont put the & in on a different query. it works. It's just that when ever i put in the "&" it just gives me the error

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2012 Oct 07, 2012

Without seeing the full code that compiles and submits the query, it's impossible to say what the problem is. Adding an ampersand should not cause a SQL error. I have just tested the following:

$conn = new MySQLi('localhost', 'root', 'secret', 'test');

$result = $conn->query("SELECT * FROM categories WHERE category LIKE 'Rock & %'");

$row = $result->fetch_assoc();

echo $row['category'];

No error is generated, and it displays "Rock & Roll".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 07, 2012 Oct 07, 2012

I put the hole code at the beginning.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 07, 2012 Oct 07, 2012
LATEST

You have only posted the SQL select statement. You have not posted any of the server side script.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines