Scooby08 Posted August 24, 2008 Share Posted August 24, 2008 I have a table in my database for all the field names that is editable, so I never know how many fields there will be.. You can add or delete rows.. I run my SELECT query to display them on the page, but I cannot think how I am supposed to write the INSERT INTO query when I don't know the how many there will be.. This INSERT INTO works right now for me, when I know what all the fields are, but if I add another field to the table this will not have that field in the INSERT INTO query.. <?php $query_customers = "INSERT INTO dw_customers (customer_name, customer_phone, customer_email) "; $query_customers .= "VALUES ('$_POST[customer_name]', '$_POST[customer_phone]', '$_POST[customer_email]') "; ?> How can that be written to insert all the fields information without knowing how many fields there will be, and do I need to create an array out of the fields like so: <input type="text" name="customers[]" /> <input type="text" name="customers[]" /> <input type="text" name="customers[]" /> or do I need to do something like this: <input type="text" name="customers_1" /> <input type="text" name="customers_2" /> <input type="text" name="customers_3" /> Any help getting me pointed into the right direction will be much appreciated.. Thanks.. Quote Link to comment Share on other sites More sharing options...
zq29 Posted August 26, 2008 Share Posted August 26, 2008 So, say your table (dw_customers) has those three fields (customer_name, customer_phone, customer_email) - If you add a forth (customer_telephone), you want your queries to automatically accommodate that addition? If I have that right, it is probably doable but I HIGHLY recommend that you don't follow that train of thought. You have two options: Design the system before you build it, not while you build it Design the database in a more efficient way To design the database to work in a way where you can add fields, I'd probably tackle it like this: customer id, name attributes id, name customer_attribute id, customer, attribute, value Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.