Jump to content

[SOLVED] An easier way to do this?


nutt318

Recommended Posts

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>";
?>

 

Link to comment
https://forums.phpfreaks.com/topic/144518-solved-an-easier-way-to-do-this/
Share on other sites

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.