colinsp Posted March 19, 2009 Share Posted March 19, 2009 I am trying to prevent the execution of my php code until the user presses the submit button on a form. I have been at this for a few hours and I'll bet its something stupid but all the Google searching is just leading me in circles. Any thoughts most welcome. <form name="new_advert" action="<?=$_SERVER['PHP_SELF'] ?>" method="POST" then all my forum input stuff, then <input type="submit" name="Submit" id="Submit" value="Submit" > </form> <?php if (isset($_POST['Submit'])) { } // wait until the submit button is pressed then the rest of my php code. It is this that is being executed when I want it to wait for the submit button. TIA Colin Link to comment https://forums.phpfreaks.com/topic/150207-solved-noob-problem-with-isset-to-prevent-execution/ Share on other sites More sharing options...
samona Posted March 19, 2009 Share Posted March 19, 2009 Submit should be submit. Lower case 's' Link to comment https://forums.phpfreaks.com/topic/150207-solved-noob-problem-with-isset-to-prevent-execution/#findComment-788810 Share on other sites More sharing options...
Zhadus Posted March 19, 2009 Share Posted March 19, 2009 Is it still executing? The code should work fine as long as you are aware that the code you want executed IF the submit button has been pressed, is inside those { & } brackets. Link to comment https://forums.phpfreaks.com/topic/150207-solved-noob-problem-with-isset-to-prevent-execution/#findComment-788813 Share on other sites More sharing options...
jackpf Posted March 19, 2009 Share Posted March 19, 2009 Submit should be submit. Lower case 's' Well, no because the name of the submit button is "Submit". However...why don't you try something like this...? if(!isset($_POST['Submit'])) { echo '<form...';//forum stuff } else { //put the stuff you want to execute here } Also, just to let you know, you don't need PHP_SELF in your form action. You can just put action="" and it does the same thing. Anyway, hope this helps. Link to comment https://forums.phpfreaks.com/topic/150207-solved-noob-problem-with-isset-to-prevent-execution/#findComment-788814 Share on other sites More sharing options...
colinsp Posted March 19, 2009 Author Share Posted March 19, 2009 Is it still executing? The code should work fine as long as you are aware that the code you want executed IF the submit button has been pressed, is inside those { & } brackets. Doh, why didn't I spot that? Thanks very much one too many } in the wrong place. Thanks for the other suggestions too. Link to comment https://forums.phpfreaks.com/topic/150207-solved-noob-problem-with-isset-to-prevent-execution/#findComment-788833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.