Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.