Title: php code not working properly
Last modified: August 19, 2016

---

# php code not working properly

 *  [nutt318](https://wordpress.org/support/users/nutt318/)
 * (@nutt318)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/php-code-not-working-properly/)
 * Well I have some php code that has a button that updates some text in .txt file.
   So I installed the plug-in Exec-PHP and I copied my code into the edit view on
   my page and the button shows up. So far the php plug-in is doing its job. Now
   for some reason when I click on my button to change the text on a file it redirects
   me back to my blogs main index.php page. When using this code on a normal .php
   page it works great. But when using it in wordpress something with how the page
   is displayed like [http://mysite.com/wordpress/?page_id=3](http://mysite.com/wordpress/?page_id=3)
   it doesn’t work.
 * Does anyone have any ideas on either how to create a new separate page or for
   this code to work properly?
 * Here is code, hopefully it shows up correctly:
 *     ```
       <?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>";
       ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [nutt318](https://wordpress.org/support/users/nutt318/)
 * (@nutt318)
 * [17 years, 1 month ago](https://wordpress.org/support/topic/php-code-not-working-properly/#post-983670)
 * Any ideas how how to do the above?
 * Also is there a way to [http://mysite.com/wordpress/test.php](http://mysite.com/wordpress/test.php)
   = [http://mysite.com/wordpress/?page_id=3](http://mysite.com/wordpress/?page_id=3)
 * Basically so that there is an actual page for test.php and not have it refer 
   to page id 3?
 * I first post php code is not fuctioning propertly due to the page id
 * Thanks for your help.

Viewing 1 replies (of 1 total)

The topic ‘php code not working properly’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [nutt318](https://wordpress.org/support/users/nutt318/)
 * Last activity: [17 years, 1 month ago](https://wordpress.org/support/topic/php-code-not-working-properly/#post-983670)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
