刷新网页会再次将数据插入数据库 [英] Refreshing a web page inserts data again to DB

查看:56
本文介绍了刷新网页会再次将数据插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有表单的php网页。在网页中填写表单后,我可以将其提交给服务器。但之后,如果我刷新页面,它会将相同的记录插入数据库。有没有解决这个问题的方法?

I've a php web page with a form. After filling the form in web page, I can submit it to the server. But after that, if I refresh the page, it inserts the same record to the database. Is there any solutions to this problem?

推荐答案

通过几个步骤做一个技巧:

1.创建会话变量名称datasubmit或者任何其他合适的名称并设置值true

ie
Do a trick with several step:
1. create a session variable name datasubmit or any other suitable name and set the value true
i.e


_SESSION ['datasubmit'] = true;在第一个文件或第一步中执行此过程。

2.保存之前更改datasubmit的值。

3.在保存数据到数据更改之前的第二步
_SESSION['datasubmit']=true; do this process in the first file or first step.
2. Before saving change the value of datasubmit.
3. In the second step before save the data to data change the value to


_SESSION ['datasubmit']的值为false。





这里是一个例如:

file form.php

_SESSION['datasubmit'] to false.


here is an example:
file form.php
<?php
session_start();


这篇关于刷新网页会再次将数据插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆