我有3个php页面,第一个我有一个表单,用户可以输入他的帐户(电子邮件地址)和他想从他的帐户中扣除的金额。 在第二个我有函数的调用和显示的成功消息。 在第三页上,函数send()完成,打开数据库连接,更改帐户金额并保存。
第一页:
<form action="send_exec.php" method="post">
Amount: <input type="number" size="24" maxlength="4"
name="points_send" min="0"><br><br>
Account<input type="text" size="24" maxlength="50"
name="email"><br><br>
<input type="submit" value="Send">
</form>
第二页(send_exec.php):
<?php
include("update_send.php");
$email = $_POST["email"];
$points_send = $_POST["points_send"];
settype ($points_send, "integer");
send($email, $points_send);
echo ("Success");
?>
第三页(update_send.php):
//some calculations are done before this to get $new_points
function send($email, $points_send)
{
$mysql_update_points = "UPDATE user SET points = ('$new_ponints') WHERE email = ('$email')";
$mysql_update = mysql_query($mysql_update_points);
}
现在的问题是,当我在第一页上执行操作而最终在第二页上执行操作时:如何在浏览器中单击F5 /重新加载以再次调用操作时如何禁用它?
答案 0 :(得分:0)
制作第四页名为“done.php”。
代码:
<?php
$pageMsg = isset($_GET['msg']) ? $_GET['msg'] : '';
if($pageMsg === "success"){
echo "Success";
} else {
echo "Error";
};
?>
然后在第三页上将您的来源更改为:
//some calculations are done before this to get $new_points
function send($email, $points_send)
{
$mysql_update_points = "UPDATE user SET points = ('$new_ponints') WHERE email = ('$email')";
$mysql_update = mysql_query($mysql_update_points);
if($mysql_update === FALSE) {
//die(mysql_error()); //Remove comment if you want to get the error.
header("Location: done.php?msg=error");
} else {
header("Location: done.php?msg=success");
};
}
从:
非常改变您的第二页(send_exec.php)<?php
include("update_send.php");
$email = $_POST["email"];
$points_send = $_POST["points_send"];
settype ($points_send, "integer");
send($email, $points_send);
echo ("Success");
?>
对此:
<?php
require_once("update_send.php");
$email = $_POST["email"];
$points_send = $_POST["points_send"];
settype ($points_send, "integer");
send($email, $points_send);
?>
答案 1 :(得分:-2)
我认为您需要检查表单是否已提交。
您可以使用以下代码进行检查: if($ _SERVER [&#34; REQUEST_METHOD&#34;] ==&#34; POST&#34;){...}
请在继续之前检查form validations ...