0. You should have known of the database schema, i.e. tables, fields, data types, and their relationships before you start coding.
1. Perform the necessary client-side validation using JavaScript for conditions such as required entry, min length, data type, etc. that will eliminate round trip to server if any of the inputs are found to be invalid. Refer:
JavaScript Form Validation[
^]
2. Next, do the necessary security related validation on the server-side such as account authentication, cleansing of user inputs, etc. See
PHP 5 Form Validation[
^]. However, you still have to perform validations on those inputs that passes the client-side validation on the server side as client-side script is clear source and opened to hacking.
3. Finally, on the database part, many measures can be put in place to ensure data integrity, such as primary key, referential integrity, and user-defined rules.
All of them work together to make sure that the application is secure and reliable.