tags:

views:

29

answers:

2

I have the current author id stored in $theauthorid I want to do a query based on the author id so I do this

query_posts('author=$theauthorid');

However it does not work unless I write the id manually. I know the id is stored correctly as I get the correct id when I echo it.

+1  A: 

double quotes instead of single ones
(manual page with explanation)

query_posts("author=$theauthorid");

but the whole approach is quite suspicious and possible dangerous
I bet we have trivial SQL injection here

I'd make it rather

 query_posts("author", $theauthorid);

with taking field name from array and value sanitizing

Col. Shrapnel
+1  A: 

The correct way is to get the variable outside the quotes. This way you can use either single or double quotes.

query_posts( 'author=' . $theauthorid );

Martijn Dwars
Technically, that's not entirely true. `query_posts( "author=$theauthorid" );` will work just fine. The reason is that PHP interprets single and double quotes differently. In single quotes, all characters are literals; a $ is just a dollar sign, etc. But in double quotes, a $ means that a variable is about to follow.
John P Bloch