我无法将数据显示代码中的变量传递给另一个数据库代码(这与数据库连接)
问题描述:
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);
}
}
?>
答
create a hidden input field with name count and pass your count variable to it
<input type="hidden" value="<?php $count?>" name="count">
so at the end of the loop it will store the final count which you can use it to iterate a for loop in your php database code.