For more security at the time of entering values in database you need to create a controller where you can validate your data before entering it in database. Below i am trying to make you understand by live example please check it.
So basically first you submit a form from your view file then in between your model (where you put your database query) and view (your form view file) you need to put a controller file where you check your all validations for the input fields and when all the validations successfully passed by the form's data you will send this data to model for query level processing.
Then after your query will successfully run model send back the return values, like true or false or whatever you want(custom values) then in controller you need to check that model return what values (true or false or your passed value), suppose I am going to pass "1" from my model if the query execute properly and send "2" if not, so depending upon this return value i will decide that where i need to send my controller now or we can say next view file with result output, so if "1" is returned i display user a message that "Thanks your values are submitted or whatever" and if not then some error message. Enjoy.