I have a table of data, which consists of 4 columns of figures, over time these figures need to be updated, so I would like to do this with a HTML form so I have added some columns to the table with inputs for the new values (I have also added these into my database), but I am really becoming stuck with whats wrong as my form inst updating any fields in my database.
Here is my table/form:
<form method="post" action="test.php" id="price-increase">
<div class="x_panel">
<div class="x_content">
<table id="tablePrice" class="display table table-striped table-bordered dt-responsive">
<thead>
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Brand Owner</th>
<th>Sales Group</th>
<th>Sales Sub Group</th>
<th>Current Net</th>
<th>Current Matrix</th>
<th>Current Band A</th>
<th>Customer Increase</th>
<th>New Invoice</th>
<th>New Net</th>
<th>New Matrix</th>
<th>New Band A</th>
<th>Incresed Date</th>
<th>Processed</th>
</tr>
</thead>
<tbody>
<?php while($res = sqlsrv_fetch_array($def, SQLSRV_FETCH_ASSOC)) : ?>
<tr>
<td>
<input type="text" name="ItemCode" id="ItemCode" class="form-control" value="<?php if(!empty($res['ItemCode'])){echo $res['ItemCode'];}?>" />
</td>
<td><?php echo $res['ItemName'];?></td>
<td><?php echo $res['BrandOwner'];?></td>
<td><?php echo $res['SalesGroup'];?></td>
<td><?php echo $res['SalesSubGroup'];?></td>
<td><?php echo $res['CurrentNet'];?></td>
<td><?php echo $res['CurrentMX'];?></td>
<td><?php echo $res['CurrentBandA'];?></td>
<td>
<input type="text" name="CustomerIncrease" id="CustomerIncrease" class="form-control" value="<?php if(!empty($res['CustomerIncrease'])){echo $res['CustomerIncrease'];}?>" />
</td>
<td>
<input type="text" name="NewInvoice" id="NewInvoice" class="form-control" value="<?php if(!empty($res['NewInvoice'])){echo $res['NewInvoice'];}?>" />
</td>
<td>
<input type="text" name="NewNet" id="NewNet" class="form-control" value="<?php if(!empty($res['NewNet'])){echo $res['NewNet'];}?>" />
</td>
<td>
<input type="text" name="NewMX" id="NewMX" class="form-control" value="<?php if(!empty($res['NewMX'])){echo $res['NewMX'];}?>">
</td>
<td><?php echo $res['NewBandA'];?>
<input type="text" name="NewBandA" id="NewBandA" class="form-control" value="<?php if(!empty($res['NewBandA'])){echo $res['NewBandA'];}?>" />
</td>
<td>
<input id="IncreaseDate" name="IncreaseDate" class="form-control " required="required" type="text" value="<?php if(!empty($res['IncreaseDate'])){echo $res['IncreaseDate'];}?>" />
</td>
<td><?php echo $res['Processed'];?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<button type="submit" id="submit" name="submit" class="btn btn-success pull-right" value="submit">Save</button>
</div>
</div>
And this is my PHP:
<?php
if(isset($_POST['submit'])){
$fields = array('ItemCode', 'CustomerIncrease','NewInvoice','NewNet','NewMX','NewBandA','IncreaseDate');
$params = array();
$setFields = array();
foreach($fields as $field) {
if (isset($_POST[$field]) && !empty($_POST[$field])) {
$params[] = $_POST[$field];
$setFields[] = $field.' = ?';
}
else {
$setFields[] = $field.' = NULL';
}
}
$query = " UPDATE po_SupplierPriceIncrease
SET '.implode(', ',$setFields).'
WHERE ItemCode = ?";
$stmt = sqlsrv_prepare($sapconn2, $query, $params);
sqlsrv_execute($stmt);
}
?>
When I click submit, nothing happens. Any Ideas?
$defreturn 1 row or multiple rows?