I'm almost there.. some people refuse to accept good clear advice when its given to them.
htmlentities is nothing to do with database security at all. It is simply used to output characters to a webpage which are normally only seen in the source code. If you do not understand this then why are you so intent on using it anyway?
I see what you're trying to do but you're trying to do it all wrong and trying to ignore us in the process. If you want to use it then fine please do. Just be sure to run a damn good debug session by echoing out all of your variables so you can see why its all gone south afterwards.
I can see you're trying to write one function that covers everything. Unfortunately it doesn't work like that. Just as with any good plan you have to know what you're doing and target specific issues with specific ideas. Not just throw everything at one issue and hope that miraculously it will work out.
In short, learn to walk. Not just walk but balance and turn on the spot. Once you can do that you can run. PHP programming is one of those languages that people jump into with a specific project in mind thinking "Hey I'm going to make that today it looks easy" and the reality is pretty different. You need to be able to read and understand the php manual at php.net, understand how to use functions, what parameters to pass to them and how to use the result properly. Also debugging your code is an acquired skill. You can't just publish code and expect it to work flawlessly (EG like your initial sample which I found problems with pretty quick). You need to be able to read, understand and debug your own code because most of the time these forums can't debug your project which is spread across 6 or 7 files all containing code. I spent years learning php and I am no expert but I can survive without asking for any help because I've learnt how to debug and created my own tools and functions to help me test ideas and debug code. I'm not an expert though but I can understand php enough to support my own projects and help others here on sitepoint and another forum.
I'm not trying to put you off, on the contrary you're clearly serious about being a php programmer because many new folk don't want to know about security at all - they're just interested in getting data into their database and don't want to worry about the added problem of sql injection etc. You've actually realised at least that your forms are your first port of call for an attacker and you're clearly concerned enough to try and block this. Thats GREAT and it is why i'm still here and not ignoring you, but you do need to listen to our advice when we give it. If you don't understand it then ASK. Don't just "Well can I still do it anyway.." type thing as it will not do you any favours and you won't learn. If you don't understand something ASK for more details. If the person who wrote it doesn't explain it to you then the chances are someone else will. If you still don't get a reply then start a new topic and ask! As soon as someone seens a topic with 0 replies they'll read it and answer if they can