Page 1 of 1

if() and unset()

Posted: Wed Oct 30, 2002 11:14 am
by Klyve1
I'm using 'if' to check if a form has been submitted and if it has Insert stuff into the dB..... but if the page is reloaded it Inserts again!
I can't seem to drop the $Submit at all.
I've tried 'unset' but no joy, can anyone point me in the right direction?

Code: Select all

<?php
if ($Submit)
{
$sql = "INSERT INTO XYZ"; 

$inserted = mysql_query($sql);

unset ($Submit);
}
?>
Cheers

?>

Posted: Wed Oct 30, 2002 11:24 am
by mydimension
lemme guess, your form and php processing is all in the same page. not a bad thing.
and the form is POSTing to itself and you if statement is catching the fact that it has been submitted. also, not a bad thing.
but then you try to refresh the page right after you submitted to it. this is where your problem lies. your browser is RE-submiting the form data and as a result $Submit is still going to be set.
hope that helps

Posted: Wed Oct 30, 2002 11:31 am
by Klyve1
Yes
Yes
& Yes!
Is there ANY way of either stopping this or dumping the $Submit variable prior to the script reading it?

Posted: Wed Oct 30, 2002 11:37 am
by mydimension
don't use the refresh button to re-request the page, rather click a link that will re-call this page. the problem does not lie in you php script, at least not inherintly, but rather the way that browsers handle posted forms in combination with the refresh button.

Posted: Wed Oct 30, 2002 11:45 am
by Klyve1
Thanks
I'd still like to find a way of turning this off though!!
I haven't tried it yet but there's going to be several pages with the same script on, will they auto-insert too or is it once again a refresh issue?

Posted: Wed Oct 30, 2002 4:59 pm
by mydimension
whenever a php page displays a form and then processes the results of that form, you will always have this refresh problem. i can't think of anycheck that you could do that would fix this problem.

Posted: Wed Oct 30, 2002 5:10 pm
by Klyve1
OK, thanks for you help

Posted: Wed Oct 30, 2002 5:18 pm
by hob_goblin
check the latest row of the database, and see if its the same as the row being inserted.

Posted: Wed Oct 30, 2002 5:23 pm
by Klyve1
Yes it is, identical