Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple sql inserts on refresh

Status
Not open for further replies.

kpdvx

Programmer
Dec 1, 2001
87
US
when a user clicks refresh on my page, the sql that was set to insert on that page, inserts again, thus creating multiple entries for the same thing. Is there any way I can catch this, and stop if from happening? i am using if ($submit) to do the form processing... any ideas?
 
Well, after the user presses the submit button and goes to the page that inserts the SQL, have that page redirect him to somewhere else. On the page that inserts the SQL, say something like "You're stuff has been added. In 3 seconds, you will be fowarded to another page." And then add some code (Javascript or HTML) to foward him to another page in that amount of time. Thus, when he presses refresh, the page that refreshes will just be the page he was fowarded to.

Hope this helps.

-Vic vic cherubini
krs-one@cnunited.com
 
would there possible be another way of doing this? maybe some $variable initialization?
 
this code works fine for me

$succesfull=mysql_insert_id(); // get id from last insert

if ($succesfull > 1) {
print ("
<HTML>
<HEAD>

<TITLE>terug</TITLE>
<META HTTP-EQUIV=\&quot;Pragma\&quot; CONTENT=\&quot;no-cache\&quot;>
<script language=\&quot;javascript\&quot;>
function move(url)
{
window.location.replace(url);
}
move('yourpage.php3');
</script>
</head>
</html>
&quot;);
}

 
or:

$succesfull=mysql_insert_id(); // get id from last insert

if ($succesfull > 1) {
header(&quot;Location: NextPage.php&quot;);
exit();
} --BB
 
set a variable on that page when the query has been run

if ($query_run)
{
run query
$query_run=TRUE;

rest of page here....

}
else
{
echo &quot;don't press refresh&quot;;
}
 
Or set the database records to unique .... how likely is it that you will want duplicate records?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top