I have a form that changes something in a SQL database, the page also displays the thing being changed. For some reason, after the change is submitted, I have to refresh the page for it to correctly display the newly changed info. I know I can make a button that refreshes the page, but the button is also being used for the submit function, is there a way to combine the two so it would refresh after it updates the SQL database?
thanks
edit: nvm I figured it out, you can use a header function after the SQL query
header("location: " . $_SERVER['REQUEST_URI']);
There is a nice pattern called Post Redirect Get.
This basically means, the submit will post to the form, it’ll do it’s work and after finishing will ask the browser to redirect to itself (response.redirect), then the next request will be a normal get request.
The purpose of this pattern is “usually” to avoid multiple hits, and also, to provide the refreshed information.
So, I think the key here is that the server side code redirects to the same page.
.
Update:
Wikipedia link with further explanation: http://en.wikipedia.org/wiki/Post/Redirect/Get