[eluser]vbsaltydog[/eluser]
The multiple errors in your code suggest that you are guessing your way through the process. It doesn't help you to encourage this tactic. If you are serious about what you are doing, you should understand why you write code a certain way. A few things that I noticed were:
You have controller logic in your model.
You were putting everything into a data array regardless of its need to be there.
Your sql logic was clearly guesswork.
You should read up on the MVC design pattern so you can understand why certain code goes in the model while other code goes in the controller. You should study the active record class if you are going to use it.
I encourage you to get better at programming but not by guessing and copy/paste. I encourage you to spend some time studying the basics before you try the advanced.