nutt318 Posted February 9, 2009 Share Posted February 9, 2009 I want to have 5 buttons on my page, each with with the following. Left, Right, Up, Down, Clear. Using only one of the php codes below works great when clicking on a button it writes its direction to the text file. The clear button however clears the text file. Now this doesnt work when I copied the code from my first button. Anyone have ideas on a better way do do this? Thanks <?php if($_POST['Submit']){ $open = fopen("test.txt","a+"); $text = "Left\n"; fwrite($open, $text); fclose($open); } echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">"; echo "<input name=\"Submit\" type=\"submit\" value=\"Left\" />\n </form>"; ?> <?php if($_POST['Submit']){ $open = fopen("test.txt","a+"); $text = "Right\n"; fwrite($open, $text); fclose($open); } echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">"; echo "<input name=\"Submit\" type=\"submit\" value=\"Right\" />\n </form>"; ?> <?php if($_POST['Submit']){ $open = fopen("test.txt","a+"); $text = "Up\n"; fwrite($open, $text); fclose($open); } echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">"; echo "<input name=\"Submit\" type=\"submit\" value=\"Up\" />\n </form>"; ?> <?php if($_POST['Submit']){ $open = fopen("test.txt","a+"); $text = "Down\n"; fwrite($open, $text); fclose($open); } echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">"; echo "<input name=\"Submit\" type=\"submit\" value=\"Down\" />\n </form>"; ?> <?php if($_POST['Submit']){ $open = fopen("test.txt","w+"); $text = ""; fwrite($open, $text); fclose($open); } echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">"; echo "<input name=\"Submit\" type=\"submit\" value=\"Clear\" />\n </form>"; ?> Quote Link to comment Share on other sites More sharing options...
.josh Posted February 9, 2009 Share Posted February 9, 2009 Your naming all of your buttons the same thing. So every one of your conditions are evaluating true. If you want to make them all the same name, then you need to execute your code based on value, not name. Quote Link to comment Share on other sites More sharing options...
nutt318 Posted February 9, 2009 Author Share Posted February 9, 2009 duh, I should have relized that. thanks. Quote Link to comment 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.