Jump to content

page refresh


henryhenry
 Share

Recommended Posts

I have a bit of an issue with refreshing pages...When you hit refresh, the script resends any SQL queries to the DB (the page is handled on the same page). This is particularly annoying on a form with INSERT queries.I have tried the following (which work but aren't great)- look up data and compare before the insert/update- make columns unique in database- redirect using headers() but can be a pain if 'headers already sent'I would love just to use a simple variable to tell me if the page was refreshed and if so not to run queries! Does anyone know a trick that can make this work?Thanks!Henry

Link to comment
Share on other sites

You can set a cookie when you do the insert, include the info that you just inserted in the cookie, and if you get a request for an insert and there is a cookie that contains the same info, then ignore the insert.Actually, the session would be better for that then cookies.

Link to comment
Share on other sites

Or you could add code to your SQL commands to not execute the commands if a table, column, cell, or anything already exists. I think that would be easier.

Link to comment
Share on other sites

Good point. It all just depends on what it is that they are doing. I suppose that I missed that part that said that he was going to be using the same form that submits the data to insert it. In that case you are definitely right.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...