title: SQL statement to populate more than one listbox at a time
body: <p>I'm trying to allow a user to specify how many rows they would like to add to the order form for the customer's purchase. This allows the user to have as many rows as needed for purchasing products rather than having a set list. I have the functionality working properly, where if you type in 3 and submit, it will give you three rows to enter in product order information.
  The problem I am running into is where I am populating a listbox with the product id and name for the user to select. It populates the first row's list box, but the following list boxes only get the " - " and not the $row[] values. It seems like it's not passing in the sql statement anymore, why is this?</p>
  
  <p>This is the area in my code where I'm running into a problem with the functionality:</p>
  
  <pre><code>&lt;?
              if (isset($_POST['update']))
              {
                  //Execute this code if the update button is clicked.
                  $num = $_POST['rows'];
  
                  for ($i=0; $i&lt;$num; $i++) { ?&gt;
  
                      &lt;tr&gt;
                          &lt;td class="inputCol2"&gt;
                              &lt;select name="'product&lt;?= $i ?&gt;"&gt;
                                  &lt;option value="selectProduct"&gt;Select Product&lt;/option&gt;
                                  &lt;!-- Populate listbox with Product ID and Product Name --&gt;
                                  &lt;?
                                  do { ?&gt;
  
                                      &lt;option value="&lt;?= $row[0]; ?&gt;"&gt;&lt;?= $row[0] . " - " . $row[2]; ?&gt;&lt;/option&gt;
  
                                  &lt;? } while($row = mysqli_fetch_array($result)) ?&gt;
  
                              &lt;/select&gt;
                          &lt;/td&gt;
                          &lt;td class="inputCol2"&gt;&lt;input type="text" name="'quantity&lt;?= $i ?&gt;" &gt;&lt;/td&gt;
                          &lt;td class="inputCol2"&gt;$&lt;input type="text" name="'unit&lt;?= $i ?&gt;" value=""&gt;&lt;/td&gt;
                          &lt;td class="inputCol2"&gt;$&lt;input type="text" name="'total&lt;?= $i ?&gt;" value="" &gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;? } ?&gt;
  </code></pre>
  
  <p>And this is my entire code:</p>
  
  <pre><code>&lt;? 
          connectDB();
  
          $sql = "SELECT * FROM product";
          $sql2 = "SELECT DISTINCT emp_id, emp_fname, emp_lname FROM employee";
          $sql3 = "SELECT DISTINCT status_id FROM salesorder ORDER BY status_id asc";
          $sql4 = "SELECT * FROM salesorder ORDER BY order_id desc";
  
          $result = mysqli_query($db, $sql) or die("SQL error: " . mysqli_error());
          $result2 = mysqli_query($db, $sql2) or die("SQL error: " . mysqli_error());
          $result3 = mysqli_query($db, $sql3) or die("SQL error: " . mysqli_error());
          $result4 = mysqli_query($db, $sql4) or die("SQL error: " . mysqli_error());
  
          $row = mysqli_fetch_array($result);
          $row2 = mysqli_fetch_array($result2);
          $row3 = mysqli_fetch_array($result3);
          $row4 = mysqli_fetch_array($result4);
  
          ?&gt;
  
      &lt;div id="order-wrap"&gt;
          &lt;form method="post" action="order.php"&gt;
              &lt;table class="orderInfo"&gt;&lt;br&gt;
                  &lt;tr&gt;
                      &lt;th class="textCol"&gt;Product Rows:&lt;/th&gt;
                      &lt;td class="inputCol"&gt;&lt;input type="text" name="rows"&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input class="update" type="submit" name="update" value="Update"&gt;&lt;/td&gt;
                      &lt;td class="inputCol"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/form&gt;&lt;!-- Order Rows --&gt;
          &lt;form class="orderform" action ="order-report.php"  METHOD = "post"&gt;
              &lt;h2&gt;Order Form&lt;/h2&gt;
              &lt;h3&gt;Piedmont Furnishings&lt;/h3&gt;
              &lt;img id="couch-img" src="couch.jpg" alt="couch"&gt;
              &lt;table class="orderInfo"&gt;
                  &lt;tr&gt;
                      &lt;th class="textCol"&gt;Order Number:&lt;/th&gt;
                      &lt;td class="inputCol"&gt;&lt;input type="text" name="orderNumber" value="&lt;?= $row4[0] + 1; ?&gt;" disabled&gt;&lt;/td&gt;
                      &lt;th class="textCol"&gt;Order Date:&lt;/th&gt;
                      &lt;td class="inputCol"&gt;&lt;input type="text" name="orderDate" value="&lt;?= date("Y-m-d") ?&gt;"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th class="textCol"&gt;Customer:&lt;/th&gt;
                      &lt;td class="inputCol"&gt;&lt;input type="text" name="customer"&gt;&lt;/td&gt;
                      &lt;td class="textCol"&gt;&lt;/td&gt;
                      &lt;td class="inputCol"&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;th class="textCol"&gt;Sales Agent:&lt;/th&gt;
                      &lt;td class="inputCol"&gt;
                          &lt;select name="salesAgent"&gt;
                              &lt;option value="selectAgent"&gt;Select One&lt;/option&gt;
                              &lt;!-- Populate listbox with Sales Agents ID --&gt;
                              &lt;?
                              do { ?&gt;
  
                                  &lt;option value="&lt;?= $row2[0]; ?&gt;"&gt;&lt;?= $row2[1] . " " . $row2[2]; ?&gt;&lt;/option&gt;
  
                              &lt;? } while($row2 = mysqli_fetch_array($result2)) ?&gt;
  
                          &lt;/select&gt;
                      &lt;/td&gt;
                      &lt;th class="textCol"&gt;Order Status:&lt;/th&gt;
                      &lt;td class="inputCol"&gt;
                          &lt;select name="orderStatus"&gt;
                              &lt;option value="selectStatus"&gt;Select One&lt;/option&gt;
                              &lt;!-- Populate listbox with Status ID --&gt;
                              &lt;?
                              do { ?&gt;
  
                                  &lt;option value="&lt;?= $row3[0]; ?&gt;"&gt;&lt;?= $row3[0] ?&gt;&lt;/option&gt;
  
                              &lt;? } while($row3 = mysqli_fetch_array($result3)) ?&gt;
  
                          &lt;/select&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
  
          &lt;!-- Where the product rows input show go ??? --&gt;
          &lt;table class="bottomTable"&gt;
              &lt;tr&gt;
                  &lt;th class="textCol"&gt;Product&lt;/th&gt;
                  &lt;th class="textCol"&gt;Quantity&lt;/th&gt;
                  &lt;th class="textCol"&gt;Unit Price&lt;/th&gt;
                  &lt;th class="textCol"&gt;Total Price&lt;/th&gt;
              &lt;/tr&gt;
          &lt;?
              if (isset($_POST['update']))
              {
                  //Execute this code if the update button is clicked.
                  $num = $_POST['rows'];
  
                  for ($i=0; $i&lt;$num; $i++) { ?&gt;
  
                      &lt;tr&gt;
                          &lt;td class="inputCol2"&gt;
                              &lt;select name="'product&lt;?= $i ?&gt;"&gt;
                                  &lt;option value="selectProduct"&gt;Select Product&lt;/option&gt;
                                  &lt;!-- Populate listbox with Product ID and Product Name --&gt;
                                  &lt;?
                                  do { ?&gt;
  
                                      &lt;option value="&lt;?= $row[0]; ?&gt;"&gt;&lt;?= $row[0] . " - " . $row[2]; ?&gt;&lt;/option&gt;
  
                                  &lt;? } while($row = mysqli_fetch_array($result)) ?&gt;
  
                              &lt;/select&gt;
                          &lt;/td&gt;
                          &lt;td class="inputCol2"&gt;&lt;input type="text" name="'quantity&lt;?= $i ?&gt;" &gt;&lt;/td&gt;
                          &lt;td class="inputCol2"&gt;$&lt;input type="text" name="'unit&lt;?= $i ?&gt;" value=""&gt;&lt;/td&gt;
                          &lt;td class="inputCol2"&gt;$&lt;input type="text" name="'total&lt;?= $i ?&gt;" value="" &gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;? } ?&gt;
                      &lt;tr&gt;
                          &lt;td class="textCol"&gt;&lt;/td&gt;
                          &lt;td class="textCol"&gt;&lt;/td&gt;
                          &lt;td class="textCol"&gt;Total Order:&lt;/td&gt;
                          &lt;td class="inputCol2"&gt;$&lt;input type="text" name="totalfinal"&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;input class="submit" type="submit" value="Submit" name="orderSubmit"/&gt; 
                  &lt;/table&gt;
              &lt;/form&gt;
              &lt;? } else {?&gt;
                      &lt;tr&gt;
                          &lt;td class="textCol"&gt;&lt;/td&gt;
                          &lt;td class="textCol"&gt;&lt;/td&gt;
                          &lt;td class="textCol"&gt;Total Order:&lt;/td&gt;
                          &lt;td class="inputCol2"&gt;$&lt;input type="text" name="totalfinal"&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;input class="submit" type="submit" value="Submit" name="orderSubmit"/&gt; 
                  &lt;/table&gt;
              &lt;/form&gt;
              &lt;? } ?&gt;
         &lt;?
              mysqli_free_result($result);
              mysqli_close($db);
          ?&gt;
      &lt;/div&gt;
  </code></pre>