nutt318 Posted February 9, 2009 Share Posted February 9, 2009 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/144513-page-refresh-acts-like-submit-button-need-some-help/ Share on other sites More sharing options...
premiso Posted February 9, 2009 Share Posted February 9, 2009 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/144513-page-refresh-acts-like-submit-button-need-some-help/#findComment-758325 Share on other sites More sharing options...
nutt318 Posted February 9, 2009 Author Share Posted February 9, 2009 thanks premiso Quote Link to comment https://forums.phpfreaks.com/topic/144513-page-refresh-acts-like-submit-button-need-some-help/#findComment-758340 Share on other sites More sharing options...
nutt318 Posted February 10, 2009 Author Share Posted February 10, 2009 Ok, now for some reason putting this code in test.php and when I click on say the left button it takes me back to index.php. Is there a way to remain on the current page as the buttons without refreshing the page? Quote Link to comment https://forums.phpfreaks.com/topic/144513-page-refresh-acts-like-submit-button-need-some-help/#findComment-758616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.