Added proper error checking to the prepared statement code.