I think you are going about it correctly. And this is a very good way to do it. But you just need to make sure that the string you are sending to mysql_query() is proper SQL syntax, and has the correct (existing) tablename, etc.
I understand the need to protect code, but if you are really stuck, then the best way to get help is to show a little code, the error message (if any), and in this example, show the SQL string that gets echoed (after PHP replaced the variable $layout with the string "user", or whatever the case may be).
Also, if $layout is the prefix to a SQL table, then you definitely want to surround it with {}, like ibbo said, so it isn't looking for a different variable.
PHP Code:
//set var
$layout = "user"
//this will NOT return "user_layout_table";
echo "$layout_password_table";
//this WILL return "user_layout_table";
echo "{$layout}_password_table";
|