I am looping through Input Box and trying to POST the captured data into Database table but i am unable to do so. Can anyone help with this.
There are Dynamic Input box i am trying to capture here and trying to populate besides a column header for every product.
Complete Code : http://clean.omegakart.com/createforcast.txt
<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].$invoice .' "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>
<?php
if(isset($_POST['btn-saveforcast']))
{
try{
foreach ($invoices as $i){
foreach( $market as $m ) {
$forcast_qtys = $_POST[$m.$i];
foreach( $forcast_qtys as $q) {
$result1 = $DB_con->prepare("INSERT INTO test(test) VALUES ($q)");
$result1->execute();
}
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
echo "<script type='text/javascript'>alert('$e')</script>";
}
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
else
{ ?>
</form>