How to insert large number of column values into database using PHP/SQL?
I am trying to insert values from a form with about 200 text fields into the database using PHP/SQL.
I am doing a HTTP POST to the insert page. But would I be able to take in 200 dif开发者_高级运维ferent valaues and insert into the database?
And is there an easier way to do it than writing PHP script for insert in a for loop by having numerical names to coloumns and textfields?
Yes, you will be able to get those 200 values. The question you have to answer is - will the user enter correctly those 200 values?
Are those 200 rows in a table, or a table with 200 columns? - if the answer is 200 columns, I would reconsider in a very serious manner design of that DB
you can insert multiple rows at once like this:
INSERT INTO example
(example_id, name, value, other_value)
VALUES
(100, 'Name 1', 'Value 1', 'Other 1'),
(101, 'Name 2', 'Value 2', 'Other 2'),
(102, 'Name 3', 'Value 3', 'Other 3'),
(103, 'Name 4', 'Value 4', 'Other 4');
to insert 4 rows
200 text fields from a single webpage?! I wonder how long the page is and how you are validating everything!
Any how, you'll have to loop through all the fields and insert them - subject to your table structure.
Could you please refine your question if you need a better answer? It is really hard for us to be of any help otherwise.
if the user doesn't need exactly 200 text fields to add 200 values, then you can use add more option, this is helpful if different users need different number of data to add.
pls check this links also
http://viralpatel.net/blogs/2009/01/dynamic-add-textbox-input-button-radio-element-html-javascript.html
this will dynamically add textboxes.. so at first you only need to create 2 or 3 textboxes, if the user needs to add more data, then they just click on add more button and new text boxes will appear so user can add more data. also the site will not get ugly. also you can add multiple rows to database.(mentioned above)
精彩评论