drwo2014 2016-11-10 16:41
浏览 44
已采纳

我无法将数据显示代码中的变量传递给另一个数据库代码(这与数据库连接)

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);
} 
 }
?>
  • 写回答

1条回答 默认 最新

  • doudi5291 2016-11-10 17:17
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?