title: Insert HTML Table cell values into MySQL
body: <p>I have a HTML Table with Dynamic Columns which increase or decrease as per the user's selection.
  I need to Insert this HTML Table in a MySQL Database table after taking inputs from the users in the front end.</p>
  
  <p><a href="https://i.stack.imgur.com/zdeZl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zdeZl.png" alt="HTML Table Output"></a></p>
  
  <p>The columns from Category to Product Name are constant post that the location column changes depending upon the user requirement.</p>
  
  <p>Once the input is made and clicked on save i need to insert this data into production table in the below format:</p>
  
  <p><a href="https://i.stack.imgur.com/uBKze.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uBKze.png" alt="enter image description here"></a></p>
  
  <p>The code that i have completed so far kindly guide me with a proper direction:</p>
  
  <pre><code>&lt;?php
      if(isset($_POST['for_post_market'])){ $market = $_POST['for_post_market']; } 
      if(isset($_POST['for_post_prod_date'])){ $date_prod = $_POST['for_post_prod_date']; } 
      if(isset($_POST['for_post_sale_date'])){ $date_sale = $_POST['for_post_sale_date']; } 
      $query = 'SELECT * FROM product WHERE prod_status="Active"';
      $stmt = $DB_con-&gt;prepare($query);
      $stmt-&gt;execute();
      while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) {
          $result[$row['prod_cat_name']][] = $row['prod_id'];
  
      }
  ?&gt;
      &lt;form method="post"&gt;
      &lt;table id="invoices" border="1" class="table table-striped table-bordered"&gt;
          &lt;thead&gt;
              &lt;col width="65"&gt;
              &lt;col width="65"&gt;
              &lt;th&gt;Category&lt;/th&gt;
              &lt;th&gt;Product ID&lt;/th&gt;
              &lt;th&gt;Product Name&lt;/th&gt;
              &lt;th hidden="true"&gt;Production Date&lt;/th&gt;
              &lt;th hidden="true"&gt;Sales Date&lt;/th&gt;
  &lt;?php
      $a=count($market);
      for($i=0;$i&lt;$a;$i++) {
          echo '&lt;th&gt;&lt;input type="hidden" value="'. $market[$i] . '"&gt;'. $market[$i] .'&lt;/th&gt;';
      }
  ?&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
  &lt;?php
      foreach($result as $id =&gt; $invoices) {
          echo '&lt;tr&gt;';
          echo '&lt;td rowspan='. count($invoices) . '&gt;' . $id . '&lt;/td&gt;';
          $count = 0;
          foreach ($invoices as $invoice) {
              if ($count != 0) {
                  echo '&lt;tr&gt;';
              }
              $count++;
  
              echo '&lt;td&gt;' . $invoice . '&lt;/td&gt;';
  ?&gt;
  &lt;?php 
              $psql = $DB_con-&gt;prepare("SELECT * FROM product WHERE prod_id='$invoice'");
              $psql-&gt;execute();
              $resultpro = $psql-&gt;fetchall(PDO::FETCH_ASSOC);
              foreach($resultpro as $line) {
              }
  ?&gt;
              &lt;td&gt;&lt;?php echo $line['prod_name']; ?&gt;&lt;/td&gt;
  &lt;?php
              echo '&lt;td hidden="true"&gt;' . $date_prod . '&lt;/td&gt;';
              echo '&lt;td hidden="true"&gt;' . $date_sale . '&lt;/td&gt;';
              $a=count($market);
              for($j=0;$j&lt;$a;$j++) {
                  echo '&lt;td&gt;&lt;input type="text" name="'. $market[$j] .' "class="form-control" maxlength="6" size="4"&gt;&lt;/td&gt;';
              }
          }
      }
      echo '&lt;/tbody&gt;';
      echo '&lt;/table&gt;';
  ?&gt;
          &lt;button type="submit" class="btn btn-default waves-effect waves-light" name="btn-saveforcast" id="btn-saveforcast"&gt;Save&lt;/button&gt;
      &lt;/form&gt;
  &lt;?php
      }
      catch(PDOException $e)
      {
          echo $e-&gt;getMessage();
      }
  
  }
  else
  {
  ?&gt;
  </code></pre>
  
  <p>Complete Code <a href="http://clean.omegakart.com/createforcast.txt" rel="nofollow noreferrer">Link</a></p>