I am trying to update multiple records within an HTML form, but it isn't writing any data back, and I am getting no errors.
The table already exists and has half of the data already in it so I need to update records, not insert.
This is my form:
<form method="post" action="test.php" id="price-increase"></form>
<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>Customer Increase</th>
<th>New Invoice</th>
<th>New Net</th>
<th>New Matrix</th>
<th>New Band A</th>
<th>Incresed Date</th>
</tr>
</thead>
<tbody>
<?php while($res = sqlsrv_fetch_array($sql, SQLSRV_FETCH_ASSOC)) : ?>
<tr>
<td><?php echo $res['ItemCode'];?></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" data-date-format="dd/mm/yyyy" class="form-control col-md-7 col-xs-12" required="required" type="text" value="<?php if(!empty($res['IncreaseDate'])){echo $res['IncreaseDate'];}?>">
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<a href="test.php">
<button type="submit" id="submit" name="submit" class="btn btn-success pull-right" value="Submit">Save</button>
</a>
</div>
This is my PHP:
<?php
if(isset($_POST['submit'])){
$itemCode = (isset($_POST['ItemCode']) && !empty($_POST['ItemCode']))?$_POST['ItemCode'] : NULL;
$customerIncrease = (isset($_POST['CustomerIncrease']) && !empty($_POST['CustomerIncrease']))?$_POST['CustomerIncrease'] : NULL;
$newInvoice = (isset($_POST['NewInvoice']) && !empty($_POST['NewInvoice']))?$_POST['NewInvoice'] : NULL;
$newNet = (isset($_POST['NewNet']) && !empty($_POST['NewNet']))?$_POST['NewNet'] : NULL;
$newMX = (isset($_POST['NewMX']) && !empty($_POST['NewMX']))?$_POST['NewMX'] : NULL;
$newBandA = (isset($_POST['NewBandA']) && !empty($_POST['NewBandA']))?$_POST['NewBandA'] : NULL;
$increaseDate = (isset($_POST['IncreaseDate']) && !empty($_POST['IncreaseDate']))?$_POST['IncreaseDate'] : NULL;
$processed = (isset($_POST['Processed']) && !empty($_POST['Processed']))?$_POST['Processed'] : NULL;
$query = " UPDATE po_SupplierPriceIncrease
SET CustomerIncrease = '$customerIncrease',
NewInvoice = '$newInvoice',
NewNet = '$newNet',
NewMX = '$newMX',
NewBandA = '$newBandA',
IncreaseDate = '$increaseDate',
Processed = '$processed'
WHERE ItemCode = '$itemCode';
";
$stmt = sqlsrv_prepare($sapconn2, $query);
sqlsrv_execute($stmt);
return $stmt;
}
?>
Like I said, it won't update and it has no errors. Am I doing something wrong here?