Improved security and error handling

Changed the query to a prepared statement.  An alert is added to the page if the query fails.