Forum Moderators: coopster

Message Too Old, No Replies

Mysql auto form building?

Building forms based on Mysql feild names any pointers?

         

lasko

7:30 am on Jul 11, 2005 (gmt 0)

10+ Year Member



Using Mysql 4 and Php 5 also working in OOP using classes and functions

Project is to allow admin to create new tables in the database through a browser.

For example - 3 content sections sport, travel, news.

In the admin area I want them to be able to create a table say "business".

Each table has different field names some will be enums, text and varchars etc.

I would appreciate some advice or pointers in the right direction for this.

Here is what I think I need to do -

Build a simple function that reads all the field names of a table into an array ready to generate the form.

I'm thinking I will have to send a "table name", "content owner ID" and "content ID" to the form building function first.

The form should then build and place the content in the fields ready for updating.

When the form is submitted I'll then send the data through another function to remove all html and scripts etc then allow the content to be updated or added to the correct "content table" using the "content id".

I will have Admin staff updating the content through the admin area including advertisers (strangers) updating content through their own seperate account area as they will be the actual owners of the content.

My question:

"Is this safe and should I be thinking of a different solution"?

Am I on the right track?

My point is I won't know what field names will be used in the future, I've always built forms seperatly but as I'm learning OOP and functions etc I've seen the light :)

I don't want to have to build forms every time a new section or table is added so the script will be part a standalone install on any server type thing, it may be used by people with no experience of php and will never touch the code so I really do need to create forms on the fly.

I know their's scripts out there already but if anyone has an example I would greatful for a link however I must understand the whole process first as this is only one part of the overall program I'm building, I'm not one for re-inventing the wheel but I won't learn with out some hands on experience.

I'm not asking for anyone to build it for me (however it would be nice) just some ideas and things to look out for whilst building it.

For example any special php functions or mysql functions to look out for that can help the process.

many thanks

coopster

11:16 am on Jul 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've written something very similar before and I'm sure others have been down this road. Just make sure, even though it is "admins" or somewhat "trusted" users that you still scrub your user-supplied data and make sure it isn't anything nasty coming in. Another idea, have you considered pulling down a copy of phpMyAdmin and reviewing the code they use? You might be able to use something there ...?