I retrieve data from the database and present some data in text boxes, so that user can edit them. But there are multiple rows that user can edit. In order to get the number of records present to the user, I have used a variable called count. But I cant use that variable in the php database code.
part of data display code
while($row = mysqli_fetch_array($result)){
echo '<form action = "UpdateItem.php" method="post">';
echo "<tr>";
echo "<td>" . $row['item_id'] . "</td>"; echo"<td ></td>";
$id[] = $row['item_id'];
echo "<td>" . $row['buyingPrice'] . "</td>";echo"<td></td>";
$sellingPrice = $row['sellingPrice'];
echo "<td>"."<input type ='text' name = \"sellingPrice".$count."\" value ='".$sellingPrice."'>"."</td>";
$stockQty = $row['stockQty'];
echo "<td>"."<input type ='text' name = \"stockQty".$count."\" value ='".$stockQty."'>"."</td>";
$count = $count + 1;
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
<div id="">
<input type="submit" class="myButton" id="btnManageStockUpdate" name="btnManageStockUpdate" value="Update" />
</div>
<?php
echo "</form>";
php database code
echo ("SellingPrice".$x);
$sellingPrice = $_POST['sellingPrice'.$x];
$stockQty = $_POST['stockQty'.$x];
$sql = "UPDATE item SET sellingPrice = $sellingPrice,stockQty = $stockQty WHERE item_id = $id[$x]";
$result = mysqli_query($dbcon,$sql);
}
}
?>