I have a create attribute called acloth'size for product and I have enabled the Use In Search Results Layered Navigation option in the backend. So while doing search, I am getting MySQL error

a:5:{i:0;s:1106:"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''size_idx.entity_id) AS `count` FROM `catalog_product_entity` AS `e`
 INNER JOIN' at line 1, query was: SELECT `acloth'size_idx`.`value`, COUNT(acloth'size_idx.entity_id) AS `count` FROM `catalog_product_entity` AS `e`
 INNER JOIN `catalogsearch_result` AS `search_result` ON search_result.product_id=e.entity_id AND search_result.query_id='26'

I am getting the error of the product attribute field name. Is there any way to allow the apostrophe (') in search for the product attribute.

2 Answers 2


Looks like the database field name is not quoted in all queries by Magento. In this case


should have been


You would have to find the core file where this "count" is generated to fix this specific issue, but there might be many more.

The only reasonable solution I see is to not use any kinds of quotes in attribute codes.


You need to use this:

echo $this->escapeHtml($_product->getName())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.