I have setup an HTML page were the user will be able to set the number
of text boxes they want to enter data in. The number of text boxes
will be saved as a hidden form variable. Below is a quick HTML code
that will show what im talking about.
<Form>
<input type="textbox" name="n1">
<input type="textbox" name="n2">
<input type="textbox" name="n3">
<input type="hidden" name="num_boxes" value="3">
When the user submits the data, it pass the info to a PHP page where
the info will be used to insert into a mysql database. What is the
best way to go about doing this? There are two methods i came up with,
and 1 will be a pain to do, and the other im not sure how to
accomplish.
1. Perform if /else statements such as
if($n1 != ""){
insert $n1 into table
}
if($n2 != ""){
insert $n2 into table
and continue upto a max value
This would work if there were 3 textboxes, however what if there are
30? Then this is extremely inefficient.
2. Save $n1 to $n3 into an array so that i could just perform a loop
for(int $i = 0; $i<$num_boxes;$i++){
insert $array[i] into table
is method two possible? If so, can someone point me in the right
direction?
Thanks for your help.