in reply to programmatic database querying

On #1, if you look at the value of $SearchOnSearchTermIDSQL, you'll probably find that it contains two ? characters. These are "placeholders" for values that need to be filled in when you execute the statement.

For instance, if you had the SQL statement SELECT * FROM person WHERE first_name = ? AND last_name = ?;, then you would call $sth->execute('John', 'Doe'); to look for John Doe or $sth->execute('Bob', 'Smith'); for Bob Smith.