Yes you can use variables to build your query. One way is to build your form, validate whether or not fields in your form are blank and if so do not process those fields. The fields that are activated use them for your query. You can also put all the database and form fields in an array and process them that way.
Also since you are using PDO you can also look into prepared statements and transactions.
There are several ways to do this. These are just a couple of possibilities.