Jump to content

Page refresh acts like submit button, need some help


nutt318

Recommended Posts

Ok, I have some code that basically rights the word 'Left' to a text file. So every time I click the Left button I want to right Left to the text file. This works but for some reason when I refresh the page it also acts like I hit the submit button.

 

Is there a better way to do this or do I have something wrong?

 

Thanks for you help.

 

<?
if($_POST['Submit']){
$open = fopen("test.txt","a+");
$text = "Left\n";
fwrite($open, $text);
fclose($open);
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<input name=\"Submit\" type=\"submit\" value=\"Left\" />\n
</form>";
}
?>

<?php
if($_POST['Submit']){
   $open = fopen("test.txt","a+");
   $text = "Left\n";
   fwrite($open, $text);
   fclose($open); 
   header("Location: {$_SERVER['PHP_SELF']}");
}

echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">";
echo "<input name=\"Submit\" type=\"submit\" value=\"Left\" />\n
</form>";
?>

 

That should fix it. Given your code, it seems as though you have register_globals turned on. I would suggest turning them off.

 

For more information see

http://www.php.net/register_globals

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.