表单提交后,数据不会在输入字段上更新,而数据库也会更新。

我已经制作了这段代码来管理商店的柜台现金,用户在输入中输入新的余额 字段并按下输入按钮。 代码更新了数据库,但没有相应地更新浏览器输入字段。
我们必须刷新页面(在浏览器中使用F5或relaod按钮)以查看更新的现金值。
请帮我输入新的 值,页面立即显示新的更新值。</ p>

 &lt;?php 
$ cash_query = mysqli_query($ link,“SELECT * FROM aks_counter”);
\ n while($ counter_row = mysqli_fetch_array($ cash_query))
{
$ counter_cash = $ counter_row ['counter_cash'];

?&gt;

&lt; div class =“container”&gt;
&lt; div id =“counter_cash”&gt;
&lt; form method =“POST”&gt;
&lt; input type =“number”name =“counter_balance”class =“input_field”value =“&lt;?php echo $ counter_cash;?&gt;“&gt;
&lt; input type =”hidden“name =”counter_hidden_​​id“value =”&lt;?php echo $ counter_row ['id'];?&gt;“&gt;
&lt; / form&gt;
&lt;?php
}
$ counter_id = $ POST ['counter_hidden​​id'];
$ counter_balance = $ _POST ['counter_b alance'];
mysqli_query($ link,“UPDATE aks_counter SET counter_cash = $ counter_balance WHERE id = $ counter_id”);
?&gt;

&amp; emsp;
&lt; h2&gt; Counter Cash&lt; / h2&gt;
&lt; / div&gt;

&lt; / div&gt;
</ code> </ pre>
</ div>

展开原文

原文

I have made this piece of code to manage counter cash on a shop, the user enters the new balance in the input field and presses the enter button. The code updates the database but it does not update the browser input field accordingly. We have to refresh the page (Using F5 or relaod button in the browser) in order to see the updated cash value. Please help me to enter the new value and the page displays the new updated value instantly.

<?php
    $cash_query = mysqli_query($link,"SELECT * FROM aks_counter");

    while ($counter_row = mysqli_fetch_array($cash_query)) 
    {
        $counter_cash = $counter_row['counter_cash'];

?>

<div class="container">
    <div id="counter_cash">
        <form method="POST">
        <input type="number" name="counter_balance" class="input_field" value="<?php echo $counter_cash; ?>">
        <input type="hidden" name="counter_hidden_id" value="<?php echo $counter_row['id']; ?>">
        </form>
<?php 
    }
        $counter_id = $_POST['counter_hidden_id'];
        $counter_balance = $_POST['counter_balance'];
        mysqli_query($link,"UPDATE aks_counter SET counter_cash=$counter_balance WHERE id=$counter_id");
?>

        &emsp;
        <h2>Counter Cash</h2>
    </div> 


</div>

duanquezhan7268
duanquezhan7268 请帮忙....我被困了....
5 年多之前 回复
douzhan1935
douzhan1935 我的代码中还没有javascript。如果需要,您可以建议javascript代码。
5 年多之前 回复
doumubi6784
doumubi6784 把你的javascript代码放在这里
5 年多之前 回复
douduiyun6125
douduiyun6125 请编辑我的代码,您的解决方案无效。
5 年多之前 回复
dsm17496
dsm17496 define$counter_cash='';在<?php和check之后的顶部。
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问