Unable to POST to Database using HTML Table

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>

Hi sumeetpujari, welcome to the forum

Is session.auto_start enabled (boolean true) in the php.ini file?

Are you getting any error messages?

There is an extra space in the input’s name attribute:

name="'. $market[$j].$invoice .' "class="form-control"
                                ^

Cleared that the code still wont POST the data from the HTML table to Database

No

If you mean no to both then $user_id = $_SESSION['user_session']; won’t work and you aren’t seeing the error message.

Try changing the beginning of the file like so (but don’t forget to comment out or remove the “only” lines if this is on a live site once you’re done.

<?php
session_start();

error_reporting(E_ALL); // for troubleshooting only
ini_set('display_errors', true); // for troubleshooting only

   require_once dirname(__FILE__) . '/config/dbconfig.php';

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.