Question

I'm sorry if this a stupid question, but I am new to this. I want to store all the information from all my customers' different contact forms in a database so they can retrieve the information later. Each contact form has a different number of fields. Ideally I'd store all of this info in one MYSQL table, but as I said each customer's contact form has a different number of fields.

I was thinking of creating a database with the following fields ID, customerID, dateTime, data The data would be the html of the contact form. However I am sure that's not best practice. Also it wouldn't allow me to offer a download option to the customer of all their contact forms as a csv or similar. I don't want to have a different table for each customer either, and I am sure having a table with 'field1', 'field2', 'field3' etc isn't that good either. Any ideas?

Was it helpful?

Solution

If you don't need it to be relational, that would be fine. You wouldn't be able to query it very easily.

You could store the answers in another table using keys to link back to the form and field.

Or use a KeyValue store type DB like MongDB, and you could store all your data without worrying about the schema.

OTHER TIPS

Make another table called user_data. In it, have:

id, user_id, data

Then, if they fill out a form with 10 fields, you can enter 10 entries into this table. When you pull data for the user, just also pull any data from the user_data table that has user_id = their id.

If you need more than that, you could also add a "field_name" field or something:

id, user_data, field_name, data

You can use the MySQL database to have a schema for your desired information that relates many tables to one another.

Here is another discussion about database design: Database Design Best Practices

If you must have only one table, the other choice I would mention is to have the ID created automatically, and then make the fields be not required. This way when a customer fills out one form before the other it won't mess you up. You can then store the ID as a Session Variable and reuse it for different INSERT statements to your database.

You can make a download function for the customer that will output in the desired format that queries your table and then generates the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top