gpt4 book ai didi

php - 如何使表单 POST 到同一页面的值(value)?

转载 作者:行者123 更新时间:2023-11-30 23:48:53 26 4
gpt4 key购买 nike

我必须让所有事情都发生在同一个页面上。我用过action="<?PHP echo $_SERVER['PHP_SELF']; ?>"在这里,但它不工作。我在表单下方插入了 PHP 查询。基本上,我的问题是如何确保表单在同一页面上发布值。如果更新,将弹出一个窗口。

$user_id=$_SESSION['user_id'];
$date = date("l jS \of F Y h:i:s A");

$query1 ="SELECT daily_limit FROM user WHERE user_id='$user_id'";
$result1 = mysqli_query($link, $query1) or die(mysqli_error($link));
while ($row1 = mysqli_fetch_array($result1)) {
$dailylimit=$row1['daily_limit'];
}

$query2 = "SELECT SUM(debit) AS debited_today FROM transaction WHERE user_id = '$user_id' AND date = CURRENT_DATE" ;
$result2 = mysqli_query($link, $query2) or die (msqli_error($link));
while ($row2 = mysqli_fetch_array($result2)){
$debited_today = $row2['debited_today'];
}

//表单

    <form method="POST" action="<?PHP echo $_SERVER['PHP_SELF']; ?>" > 
<table id="table">
<tr>
<td class="alt">Existing Daily Limit</td>
<td>S$ <?php echo $dailylimit; ?> </td>
<input type="hidden" name="dailylimit" value="<?php echo $dailylimit ?> "/>
</tr>
<tr>
<td class="alt"><label for="newdailylimit">New Daily Limit</label></td>
<td>$ <select name="newdailylimit">
<option value="100.00">100.00</option>
<option value="500.00">500.00</option>
<option value="1000.00">1000.00</option>
<option value=5000.00">5000.00</option>
</select></td>
</tr>
<tr>
<td class="alt">Amount Debited Today</td>
<td>S$ <?php echo $debited_today; ?></td>
</tr>
<tr>
<td class="alt">Amount Debited Left</td>
<td>S$ <?php echo ($dailylimit - $debited_today); ?> </td>
</tr>
</table>
<br/>
<input type="submit" name="submit "value="Submit"></input>
</form>

//我需要发布的值

$dailylimit = $_POST['dailylimit'];
$newdailylimit = $_POST['newdailylimit'];

if ($dailylimit != $newdailylimit){
$query = "UPDATE user SET daily_limit='$newdailylimit' WHERE user_id='$user_id'";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
echo "<script>alert('You have successfully updated your daily limit');</script>";
}
else if ($dailylimit == $newdailylimit){
echo "<script>alert('You have selected the same daily limit as your previous one. Please choose a different one. ');</script>";
}
else{

}

最佳答案

啊,我可能已经发现问题所在了:

submit 之后有一个空格,value 之前没有空格。

这将阻止您提交表单。

<input type="submit" name="submit "value="Submit"></input>
---^ ^

将此更改为:

<input type="submit" name="submit" value="Submit">

双引号可能会把事情搞砸。


其他错误但不能解决您的问题

还有

<option value=5000.00">5000.00</option>

应该是

<option value="5000.00">5000.00</option>

还有

<input type="hidden" name="dailylimit" value="<?php echo $dailylimit ?> "/>
// You have an extra space here ^

这将更改您的 $dailylimit,并在其后附加一个空格。

关于php - 如何使表单 POST 到同一页面的值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21290128/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com