title: Dynamically generated "submit" buttons in PHP
body: <p>First time posting here (so please be gentle, as I am a relative PHP newbie).</p>
  
  <p>I am building an intranet for our company and one of the things I need to do is to create a form that lists all outstanding sales orders (pulled from our accounting database) and provides a "submit" button beside each one to create the relevant work order. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>            &lt;div class="report_column"&gt;
  
          &lt;div class="report_header"&gt;
              &lt;div class="report_column_title" style="width:150px;margin-left:5px"&gt;ship date&lt;/div&gt;
              &lt;div class="report_column_title" style="width:200px"&gt;customer&lt;/div&gt;
              &lt;div class="report_column_title" style="width:140px;text-align:right"&gt;item&lt;/div&gt;        
              &lt;div class="report_column_title" style="width:120px;text-align:right"&gt;quantity&lt;/div&gt;
          &lt;/div&gt;
  
      &lt;?php
  
          // Open connection
          include 'includes/dbconnect.php'; 
  
          // Perform query
          $result = mysqli_query($con,"SELECT * FROM tSalOrdr ORDER BY dtShipDate ASC");
  
          // Retrieve results
          while($row = mysqli_fetch_array($result)) {
  
              $order = $row['lId'];
  
              if ($row['bCleared'] == 0) {
  
                  $shipdate = substr($row['dtShipDate'], 0,10);
                  $customer = $row['sName'];
                  $po = $row['sComment'];
  
                  echo '&lt;div class="report_item" style="width:750px";&gt;';
  
                  echo '&lt;form class="form" action="index.php?page=form&amp;item=create_work_order" method="POST"&gt;';
  
                      echo '&lt;div class="report_item_date" style="width:120px"&gt;'.$shipdate.'&lt;/div&gt;';
                      echo '&lt;div class="report_item_name" style="width:530px"&gt;'.$customer;
  echo '&lt;input type="hidden" name="po" value="'.$po.'" /&gt;';                       
  echo '&lt;input type="submit" class="submit" style="height: 25px;width:100px;margin:0px;padding:0px;margin:0px" value="work order"/&gt;';
                      echo '&lt;/div&gt;';
  
                      $result2 = mysqli_query($con,"SELECT * FROM tSOLine WHERE lSOId=$order ORDER BY sDesc ASC");
                      while($row = mysqli_fetch_array($result2)) {
  
                          if ($row['dRemaining'] &lt;&gt; 0) {
  
                              echo '&lt;div class="report_item_details"&gt;';
                                  echo '&lt;div class="report_item_item"&gt;'.$row['sDesc'].'&lt;/div&gt;';
                                  echo '&lt;div class="report_item_quantity"&gt;'.$row['dRemaining'].'&lt;/div&gt;';
                              echo '&lt;/div&gt;';
                          }
                      }
  
                  echo '&lt;/form&gt;'; 
  
                  echo '&lt;/div&gt;';              
  
              }
          }
  
          // Close connection
          mysqli_close($con);
  
      ?&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>What happens when I do this is that the first "submit" button will, for some reason, send me back to "index.php". The other buttons will load the correct page, however, they do not POST the required value.</p>
  
  <p>Is there something I am doing wrong or is this something that needs different methodology than what I am currently using? My research on this seems to indicate that perhaps I should use javascript or an array to deal with this, but, having never dealt with either, I am not sure how to proceed. Any pointers would be appreciated.</p>
  
  <p>Thanks.</p>
  
  <p>@maniteja: The index.php is as follows:</p>
  
  <pre><code>         &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
  
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;meta name="language" content="en" /&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link href="css/main.css" rel="stylesheet" type="text/css" /&gt;
      &lt;link href="css/forms.css" rel="stylesheet" type="text/css" /&gt;
      &lt;link rel="icon" type="image/ico" href="favicon.ico" /&gt;
      &lt;script type="text/javascript" src="scripts/jquery-2.1.0.min.js" &gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="scripts/tabcontent.js" &gt;&lt;/script&gt;   
  &lt;/head&gt;
  
  &lt;body&gt;
  
      &lt;!-- BEGIN MAIN CONTENT --&gt;
      &lt;div id="wrapper"&gt;
  
      &lt;!-- BEGIN HEADER --&gt;
      &lt;div id="header"&gt;
          &lt;img src="images/logo.jpg"&gt;
      &lt;/div&gt;
      &lt;!-- END HEADER --&gt;
  
      &lt;!-- BEGIN MAIN MENU --&gt;
      &lt;div id="leftcolumn"&gt;
          &lt;?php include 'includes/menu.php'; ?&gt;
      &lt;/div&gt;
      &lt;!-- END MAIN MENU --&gt;
  
      &lt;!-- BEGIN CONTENT FRAME --&gt;
      &lt;div id="rightcolumn"&gt;
          &lt;div id="content_area"&gt;
              &lt;?php
                  if (isset($_GET['page'])) 
                  {$page = $_GET['page'];
                  include('pages/' . $page . '.php');}
                  else {include('pages/home.php');}
              ?&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;!-- END MAIN CONTENT --&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>I've made seventeen other forms with it, so I don't think that it is the problem. I'm hoping that this is just a typo or a logic error on my part.</p>