Quotes in table name

How can I fix this?

You can’t, but it isn’t broken. You are telling prepare to use a string. A string will be quoted. It isn’t meant to generate MySQL syntax, which is what you are asking it to do. Your tablename is more a MySQL command or keyword than a string value. That isn’t what prepare is for.

prepare is meant to operate on user supplied data. Your tablename is not– well, shouldn’t be– user supplied data so you don’t need to “prepare” it. It is unnecessary. Just construct the tablename in the SQL itself:

"SELECT COUNT(id) FROM ".$wpdb->prefix."faq_questions WHERE answer !=' '"

See: https://wordpress.stackexchange.com/a/93861/21376

Leave a Comment