Bugfix hard-coded database table names

Fixed error in a database query as reported by [Watch Teller](http://wordpress.org/support/profile/watchteller).

Database table names were hard-coded instead of using the $wpdb properties.

Also verified that this didn't occur anywhere else in the whole application and wrapped the offending query in a $wpdb->prepare().