好吧,我被強制將此功能備份到我的上級。但是這次數據將會在沒有AJAX POST方法的情況下被更新。更改按鈕提交的單元格值
在我的表中我有一個減號按鈕和一個加按鈕。每個作爲一個提交按鈕,當一個值被添加到不同的輸入字段時,計數將基於哪個按鈕被點擊而改變,例如(當輸入字段爲10時,如果加上按鈕則點擊+10)
我的表格不會更新,只要發生錯誤,就無法獲得任何迴應。 感謝您的幫助。
<?php
if(isset($_GET['stock_id'])) {
$the_stock_id = mysqli_real_escape_string($connection, $_GET['stock_id']);
}
$query = 'SELECT stock_id, sku_number, category, description, price, in_stock ';
$query .= 'FROM parts_stock AS a JOIN items AS b ON a.stock_id = b.s_id ';
$query .= "WHERE a.stock_id =".$the_stock_id;
$edit_sku = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($edit_sku)) {
$stock_id = $row['stock_id'];
$sku = $row['sku_number'];
$category = $row['category'];
$desc = $row['description'];
$price = $row['price'];
$stock = $row['in_stock'];
}
if(isset($_POST['update_stock'])) {
$price = $_POST['price'];
$mod_stock = $_POST['mod_stock'];
if(isset($_POST['rem_stock'])) {
$stock -= $mod_stock;
echo $stock;
}elseif(isset($_POST['add_stock'])) {
$stock += $mod_stock;
echo $stock;
}
$query = "UPDATE parts_stock, items SET ";
$query .= "price = '$price', ";
$query .= "in_stock = '$stock' ";
$query .= "WHERE stock_id ='$the_stock_id' ";
$update_stock = mysqli_query($connection, $query);
confirmQuery($update_stock);
$alert = <<<DELIMETER
<div class='alert alert-warning alert-dismissible fade in' role='alert'>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>Inventory Updated!</strong> <a href='inventory.php?view_all_inventory'>View All Inventory</a>
</div>
DELIMETER;
}
?>
<div class="col-xs-12 col-sm-12 col-md-12">
<h2>Edit Inventory Item</h2>
<?php echo $alert; ?>
<hr>
<table class="table table-bordered table-responsive table-striped">
<thead class="thead-inverse">
<tr class="alert alert-success">
<th>SKU #</th>
<th>Category</th>
<th>Description</th>
<th>Price</th>
<th>Current Stock</th>
<th>+/- Stock</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<form role='form' action="" method="POST">
<td><input value="<?php echo $sku; ?>" type="text" class="form-control" name="sku_number" readonly ></td>
<td><input value="<?php echo $category; ?>" type="text" class="form-control" name="category" readonly></td>
<td><input value="<?php echo $desc; ?>" type="text" class="form-control" name="description" readonly></td>
<td><input value="<?php echo $price; ?>" type="text" class="form-control" name="price" ></td>
<td><input value="<?php echo $stock; ?>" type="text" class="form-control" name="in_stock" readonly ></td>
<td><input value="" type="text" class="form-control" name="mod_stock"> </td>
<td class='btn-group'>
<button class='btn btn-danger btn-sm' type='submit' name='update_stock' value='rem_stock'><i class='glyphicon glyphicon-minus'></i></button>
<buton class='btn btn-success btn-sm' type='submit' name='update_stock' value='add_stock'><i class='glyphicon glyphicon-plus'></i></buton>
</td>
</form>
</tr>
</tbody>
</table>
</div>
使用'if($ _POST ['update_stock'] =='rem_stock')...' –