title: retrieving post values from form with dynamic element names
body: <p>I'm trying to retrieve the post values from a form where the element names are based on values from a recordset.  Here is the form:</p>
  
  <pre><code>$recordID = $_GET["recordID"];
  $colour_result = mysqli_query($con,"SELECT colour_variation.*, colours.* FROM colour_variation INNER JOIN colours ON colour_variation.colour_id=colours.colour_id WHERE product_code='$recordID'");
  while($colour_row = mysqli_fetch_array($colour_result))
    {
   ?&gt; 
  &lt;tr&gt;&lt;td valign="middle"&gt;&lt;img src="resources/images/colours/&lt;?php echo $colour_row['colour_image']; ?&gt;" width="35" height="35"&gt;&lt;/td&gt;&lt;td width="100"&gt;&lt;?php echo $colour_row['colour_name']; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;center&gt;&lt;?php if($colour_row['xs'] !== '') { echo('&lt;input type="text" size="2" name="xs_&lt;?php echo $colour_row[colour_name]; ?&gt;" id="xs_&lt;?php echo $row[colour_name]; ?&gt;" placeholder="Qty"&gt;');
       } else { echo(''); } ?&gt; &lt;/center&gt;&lt;/td&gt;
      &lt;td&gt;&lt;center&gt;&lt;?php if($colour_row['s'] !== '') { echo('&lt;input type="text" size="2" name="s_&lt;?php echo $colour_row[colour_name]; ?&gt;" id="s_&lt;?php echo $row[colour_name]; ?&gt;" placeholder="Qty"&gt;');
       } else { echo(''); } ?&gt; &lt;/center&gt;&lt;/td&gt;
      &lt;td&gt;&lt;center&gt;&lt;?php if($colour_row['m'] !== '') { echo('&lt;input type="text" size="2" name="m_&lt;?php echo $colour_row[colour_name]; ?&gt;" id="m_&lt;?php echo $row[colour_name]; ?&gt;" placeholder="Qty"&gt;');
       } else { echo(''); } ?&gt; &lt;/center&gt;&lt;/td&gt;
      &lt;td&gt;&lt;center&gt;&lt;?php if($colour_row['l'] !== '') { echo('&lt;input type="text" size="2" name="l_&lt;?php echo $colour_row[colour_name]; ?&gt;" id="l_&lt;?php echo $row[colour_name]; ?&gt;" placeholder="Qty"&gt;');
       } else { echo(''); } ?&gt; &lt;/center&gt;&lt;/td&gt;
      &lt;td&gt;&lt;center&gt;&lt;?php if($colour_row['xl'] !== '') { echo('&lt;input type="text" size="2" name="xl_&lt;?php echo $colour_row[colour_name]; ?&gt;" id="xl_&lt;?php echo $row[colour_name]; ?&gt;" placeholder="Qty"&gt;');
       } else { echo(''); } ?&gt; &lt;/center&gt;&lt;/td&gt;
      &lt;td&gt;&lt;center&gt;&lt;?php if($colour_row['xxl'] !== '') { echo('&lt;input type="text" size="2" name="xxl_&lt;?php echo $colour_row[colour_name]; ?&gt;" id="xxl_&lt;?php echo $row[colour_name]; ?&gt;" placeholder="Qty"&gt;');
       } else { echo(''); } ?&gt; &lt;/center&gt;&lt;/td&gt;
      &lt;td&gt;&lt;center&gt;&lt;?php if($colour_row['xxxl'] !== '') { echo('&lt;input type="text" size="2" name="xxxl_&lt;?php echo $colour_row[colour_name]; ?&gt;" id="xxxl_&lt;?php echo $row[colour_name]; ?&gt;" placeholder="Qty"&gt;');
       } else { echo(''); } ?&gt; &lt;/center&gt;&lt;/td&gt;
      &lt;td&gt;&lt;center&gt;&lt;?php if($colour_row['one_size'] !== '') { echo('&lt;input type="text" size="2" name="one_size_&lt;?php echo $colour_row[colour_name]; ?&gt;" id="one_size_&lt;?php echo $row[colour_name]; ?&gt;" placeholder="Qty"&gt;');
       } else { echo(''); } ?&gt; &lt;/center&gt;&lt;/td&gt;
  
      &lt;/tr&gt;
      &lt;?php } ?&gt;
  &lt;/table&gt;
  &lt;input type="hidden" name="product_code" value="&lt;?php echo $row_products['product_code']; ?&gt;" &gt;
  </code></pre>
  
  <p>I tried this to get them out but its not working:</p>
  
  <pre><code>&lt;?php 
  $product_code=$_POST["product_code"];
   foreach ($_POST as $key =&gt; $value) {
          if (substr($key, 0, 2) == "xs_") {
              $colour_name[str_replace("xs_", "", $key)] = $value;
          }
          echo $key;
          echo '&lt;br /&gt;';
          echo $value;
      }
  
  
  ?&gt;
  </code></pre>
  
  <p>there could be any number of colours per product.  Any help on getting the values to display on next page with the qty selected per colour/size would be much appreciated.</p>
  
  <p>thanks</p>