Click here to Skip to main content
14,488,855 members
Rate this:
Please Sign up or sign in to vote.
See more:
When i refresh the page the datas are inserting to database.How can i avoid this?

Uday P.Singh 22-Oct-11 3:08am
can you post your code?
sreenathpktr 22-Oct-11 3:10am it is..

$ins=mysql_query("insert into it_clearance2 values('$k','$l')");
$msg="IT clearance record saved successfully";
header("Refresh:3; url=it.php");

$msg="Error occured..";
Rate this:
Please Sign up or sign in to vote.

Solution 2

the HTTP protocol is stateless and no matter what you do, $_POST will always contain the same data coz thats what browsers do, they save the POST data and which is why the $btn is never unset or emptied and which in turn is why it keeps inserting into the table.

Having said that, what you can probably try doing is, don't refresh the page and as soon as the values are inserted the first time and you have a result $msg, redirect to a different page to show that message. You can append that message in querystring of the redirected to URL or you can put it in a session and retrieve it on the other page.

Hope this helps...

EDIT: move the call to header() function outside the if else if you want the failure message to be conveyed to the redirected to page.

Rate this:
Please Sign up or sign in to vote.

Solution 1

Plz provide your code for solution
I.explore.code 22-Oct-11 5:31am
you put this in comments not in solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100