Another hand wringer

From: Date: Sun, 18 Feb 2007 21:06:54 +0000
Subject: Another hand wringer
Groups: php.general 
Request: Send a blank email to php-general+get-248998@lists.php.net to get a copy of this message
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
   $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 code
I 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

« previous php.general (#248998) next »