This is a great point from @ginerjm Mixing "presentation" and "logic" is the best way to have hard to maintain code. PHP is intrinsically a templating product, in that you can put partial html scripts and include them easily. There are also numerous excellent and easy to integrate template systems.
If you can separate the database/model related code from all the other code that is really just html, it will be easier to see how to approach things in a simple and maintainable way. The concept is certainly related to KISS and to breaking larger blocks of complicated interdependent code down into discreet functions that do one thing in a predictable way.
From a database standpoint, your comment that "it creates a duplicate entry in my database if the value was already checked" also tells you that you are not using features of the database engine that will provide you data integrity. You can use constraints/indexes, as well as "UPSERTS" to help manage this. I would provide further examples, but I have no idea from your code snippets what your database looks like.