Forum Moderators: coopster
I have a form where the user enters a number in an input field and hits submit.
Based on the number the user enters - a number of new textareas will become available on the following page. The new textareas are named in number order (tdata1,tdata2,tdata3,tdata4) - Now when this page is submitted is where I am encountering a problem.
I need to print the values of these textareas from the previous page, but since I don't have a way of knowing how many there are going to be, I assume it needs to be in an array of sorts. I'm currently using POST to send the variables.
... I had no clue how to approach this, so I tried to do the following:
variable nof is the nuber that was entered on the first page, and also t
he number of input fields that were created on the second page.
$nof = $_POST['fnum'];
$i=0;
while ($i < $nof){
$var1 = $_POST['tdata1'];
$i++
}
I need var1 to incriment also... $var2 for tdata2, $var3 for tdata3, and so forth...
Any help would be greatly appreciated... I would be more than happy to share the URLs and full code. Thanks for you time folks.
$nof = $_POST['fnum'];
$i=1;
while ($i <= $nof){
$varname = "var$i";
$$varname = $_POST["tdata$i"];
$i++
}
You don't like for loops?
for($i = 1; $i <= $nof; $i++) {
$varname = "var$i";
$$varname = $_POST["tdata$i"];
}
A more concise yet maybe little harder to understand syntax is:
for($i = 1; $i <= $nof; $i++) {
${"var$i"} = $_POST["tdata$i"];
}