刷新页面后如何停止插入

How can I stop a insert into query after refreshing a page, after the post is done, so it won't put in all the post variables again after a refresh?

Thanks in advance!

After the data has been inserted to the database, redirect and exit.

header('location: thepage.php');
exit;

Make your query look like this:

insert into table
(field1, field2, etc)
select value1, value2, etc
from somesmalltable 
where not exists
(subquery to check for existing records)

Or you can set a session variable and update it once the query has been written, if the value = 1 then dont execute the query again

There are two ways you can solve it:

  1. before inserting into the Database, check if the record already exist(I hope you have a primary key on the table so you can use this one)

  2. You can set a session variable in your code after inserting into the DB. After reloading, you have to check if you have set the session-variable. If yes, you can skip the inserting. If no, you can insert into DB