dongni9825 2012-09-17 14:20
浏览 95
已采纳

查询运行的次数与刷新次数一样多

If possible i'd need help with a reload thing. I mean i have this query, which gets submitted in one page, there is this profile registration, user enters his name and surname, then he proceeds in the next page entering more specific details. if a user reloads the page i.e 4 times, that's the number of times that the user's information get inserted in the database.

is there any reload function to prevent the submission of the query? I haven't tried anything, if you would ask me that, because i don't know how to start. the only clue i have is about using ajax, but is there any php way to do this?

Thanks

  • 写回答

2条回答 默认 最新

  • du958642589 2012-09-17 14:23
    关注

    You should follow the POST-Redirect-GET pattern and ALWAYS redirect after a successful POST:

    Without seeing your code, you'll need a redirect like this:

    if($inserted){
        header('Location: mypage.php?msg=reg_success');
        exit;
    }
    

    Then, on mypage.php, you could so something like:

    if(isset($_GET['msg'])){
    
        switch($_GET['msg']){
    
            case 'reg_success':
                echo 'Registration successful!';
            break;
    
        }
    
    }
    

    Or, you could create an array for success messages:

    $success_messages = array(
        'reg_success' => 'Registration successful!',
        'logout_success' => 'Logged out!'
    );
    

    And then on mypage.php:

    if(isset($_GET['msg']) && array_key_exists($_GET['msg'], $success_messages)){
        $msg_index = $_GET['msg'];
        echo $success_messages[$msg_index];
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?