Re: Another hand wringer
| From: | Matt Zandstra | Date: | Sun, 18 Feb 2007 21:51:12 +0000 |
| Subject: | Re: Another hand wringer | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-248999@lists.php.net to get a copy of this message | ||
Looks to me as if you're treating $flen as an array in one place and as a value in another:
String here:
Array here:$flen = $_POST['flen']; // length of text field group, shows to be the
Remove the count() and you'll probably get what you expect. hth On Sun, 18 Feb 2007, jekillen wrote:for($i = 0; $i < count($flen); $i++)
Hello; I am having trouble with a loop in scripts run under php v5.1.2. I have produced a form in a web page that has a variable number of text fields. These fields represent the result of opening a file and populating the fields with the corresponding value data found in the file. The field names are generated in a php loop using an iterator $i and given a_$i+1 names. If I test for the field names on post literally, a_1, a_2, a_...n, the values are getting posted properly. Then when I run through a loop looking for $_POST["a_$z"] (where $z = $i +1) only one $_POST value with this name series is processes and the loop quits. Here is the post processing code at this stage of the script: $edata = array(); $part = ''; $flen = ''; $file = ''; if($_POST['section']) { $part = $_POST['section']; // target file section-- getInstance() http://www.getinstance.com$flen = $_POST['flen']; // length of text field group, shows to be the correct number $file = $_POST['df']; // file to work on$z = 1; switch($part){ case 'name': /* a_1, a_2 etc are field names printing these values shows that all the fields are being posted properly array_push($edata, $_POST["a_1"]); array_push($edata, $_POST["a_2"]); array_push($edata, $_POST["a_3"]); array_push($edata, $_POST["a_4"]); could be as few as 1 and as many as 13 fields */ for($i = 0; $i < count($flen); $i++) { array_push($edata, $_POST["a_$z"]); // this loop terminates on the first iteration. print $_POST["a_$z"].'<br>'; // only prints the first in the series. $z++; }; //edit_pa_rec($edata, $file, $flen, $part); break; -----> more cases with similar codeI want to avoid hard coding the $_POST variables so, question, is this: A: a bug? B: $_POST data is getting dropped in the loop? C: Something else is wrong with my code? Thanks in advance Jeff K