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.
The columns from Category to Product Name are constant post that the location column changes depending upon the user requirement.
Once the input is made and clicked on save i need to insert this data into production table in the below format:
The code that i have completed so far kindly guide me with a proper direction:
<?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->prepare($query);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$result[$row['prod_cat_name']][] = $row['prod_id'];
}
?>
<form method="post">
<table id="invoices" border="1" class="table table-striped table-bordered">
<thead>
<col width="65">
<col width="65">
<th>Category</th>
<th>Product ID</th>
<th>Product Name</th>
<th hidden="true">Production Date</th>
<th hidden="true">Sales Date</th>
<?php
$a=count($market);
for($i=0;$i<$a;$i++) {
echo '<th><input type="hidden" value="'. $market[$i] . '">'. $market[$i] .'</th>';
}
?>
</thead>
<tbody>
<?php
foreach($result as $id => $invoices) {
echo '<tr>';
echo '<td rowspan='. count($invoices) . '>' . $id . '</td>';
$count = 0;
foreach ($invoices as $invoice) {
if ($count != 0) {
echo '<tr>';
}
$count++;
echo '<td>' . $invoice . '</td>';
?>
<?php
$psql = $DB_con->prepare("SELECT * FROM product WHERE prod_id='$invoice'");
$psql->execute();
$resultpro = $psql->fetchall(PDO::FETCH_ASSOC);
foreach($resultpro as $line) {
}
?>
<td><?php echo $line['prod_name']; ?></td>
<?php
echo '<td hidden="true">' . $date_prod . '</td>';
echo '<td hidden="true">' . $date_sale . '</td>';
$a=count($market);
for($j=0;$j<$a;$j++) {
echo '<td><input type="text" name="'. $market[$j] .' "class="form-control" maxlength="6" size="4"></td>';
}
}
}
echo '</tbody>';
echo '</table>';
?>
<button type="submit" class="btn btn-default waves-effect waves-light" name="btn-saveforcast" id="btn-saveforcast">Save</button>
</form>
<?php
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
else
{
?>
Complete Code Link


{and}so we can be sure what it is you think you are doing before we attempt to make any suggestions