doushui3061 2015-11-25 10:29
浏览 80
已采纳

成功页面的PHP Reload(F5)将再次调用数据库更新

I have 3 php pages, on the first I have a form where the user can enter his account (email adress) and the amount he wants to deduct from his account. On the second I have the call of the function and the sucess message shown. On the third page the function send() is done, which open the DB connection, change the amount for the account and save it.

First page:

<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>

Second page (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");
?> 

Third page (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);
}

Problem is now that when I perform the action on the first page and I end up on the second: How can I disable that when just clicking F5 / reload in my browser that the action is called again?

  • 写回答

2条回答 默认 最新

  • douji9518 2015-11-25 10:52
    关注

    Make a fourth page called "done.php".

    Code:

    <?php
    $pageMsg = isset($_GET['msg']) ? $_GET['msg'] : '';
    
    if($pageMsg === "success"){
          echo "Success";
       } else {
          echo "Error";
       };
    ?>
    

    Then on the third page change your source to this:

    //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");
        };
    }
    

    Lastely change your second page(send_exec.php) from:

    <?php
    include("update_send.php");
    $email = $_POST["email"];
    $points_send = $_POST["points_send"];
    settype ($points_send, "integer"); 
    send($email, $points_send);
    echo ("Success");
    ?> 
    

    To this:

    <?php
    require_once("update_send.php");
    $email = $_POST["email"];
    $points_send = $_POST["points_send"];
    settype ($points_send, "integer"); 
    send($email, $points_send);
    ?> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开