For inserting into database to a text field no checking is needed at all. The only thing I would check is the string length, if it’s very long it can generate very long queries and put some stress on the server, however nothing serious should happen. When mysql is running in strict mode it will throw errors when you try to insert a string that is longer than the db field allows, otherwise it will be truncated.
The form fields have lengths of input on the form
Think of them only as a usability enhancers but don’t trust them. Check for length in php.
I use
preg_match to check names etc only have certain character input
This doesn’t have anything to do with inserting into the db, but of course it’s worth doing it depending on the type of field. Actually, it’s a good idea to validate all the necessary fields but you need to treat each field individually depending on it’s purpose.
FILTER_SANITIZE_SPECIAL_CHARS to again check unauthorised characters can be used
No - escaping characters should not be done before inserting data to db but when retrieving, based on the target medium. In the future you might want to use your data for other purposes than sending to the browser as html (for example sending in a mail message, creating a pdf or even sending it to the browser as javascript). Also, string manipulations are much harder on escaped data, you would need to unescape them first. Always escape before sending data to the target medium - in this case in your html template.
mysqli_real_escape_string again to check for unauthorised characters
You should use this function for all string inserts - it doesn’t check for anything but escapes all characters so that they can be inserted accurately and safely.
Apart from that I used a php generated number on the fly the user need to enter to prevent multiple form uploads
This is one of the techniques to prevent multiple submissions, a generated number is fine.
Quite often I use trim() on text fields before inserting into db - not really a security check but it gets rid of unwanted spaces that can appear unknowingly.