Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I just simply want to execute a SQL sentence inside of a post (i am using EXEC-PHP widget for that).

The problem are the quotes when i want to do something like

$my_name='hello'

"select * from Table where name='$my_name'";

getting wrong quotes.... select * from Table where name=‘hello‘

i have tried streepslashes_deep, addslashes, stripslashes...

I think it shouldnt be so difficult... maybe its not my best day

any help?

thanks!

share|improve this question

3 Answers 3

if you're communicating with the WordPress database itself, try using $wpdb->prepare() on your select string before running it as $wpdb->query() - it should format it for you.

Further reading: Codex

share|improve this answer

Perhaps the plugin is modifying your single quotes. Double quotes are valid in SQL. What happens if you use double quotes and escape them?

e.g. "select * from Table where name=\"$my_name\"";

share|improve this answer

Try seperating and concatenating stringss:

'select * from Table where name="'.$my_name.'"'; 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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