Title: PHP Variable in Tablepress
Last modified: August 22, 2016

---

# PHP Variable in Tablepress

 *  Resolved [bbthoms](https://wordpress.org/support/users/bbthoms/)
 * (@bbthoms)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/php-variable-in-tablepress/)
 * Hi Tobias,
 * Folgendes Szenario:
 * Ich habe ein Seiten Template für eine Unterseite. Auf dieser Seite befindet sich
   ein Formular, welches direkt auch dort verarbeitet bzw. in Variablen via POST
   umgewandelt werden (klappt wunderbar). Möchte ich aber nun die Variablen in einer
   Tablepress Tabelle verwenden (ebenfalls auf der Seite eingebunden), sagt mir 
   der Debugger immer die Variable sei nicht definiert.
 * Ich habe es mit global probiert aber egal was ich mache es kommt nichts an.
 * Hast du eine Idee woran es liegen könnte?
 * Viele Grüße
    bbthoms
 * [https://wordpress.org/plugins/tablepress/](https://wordpress.org/plugins/tablepress/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/php-variable-in-tablepress/#post-5646171)
 * Hi,
 * thanks for your post, and sorry for the trouble.
 * As these are the English-language forums, I’ll reply in English, so that more
   people can benefit from the discussion. I hope that’s ok.
 * I assume that you are refering to the TablePress “PHP in tables” Extension here?
   
   Can you then maybe post some of your PHP code that you have in the table cells?
 * Regards,
    Tobias
 *  Thread Starter [bbthoms](https://wordpress.org/support/users/bbthoms/)
 * (@bbthoms)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/php-variable-in-tablepress/#post-5646333)
 * Hi Tobias,
 * oh yes you’re right. Where I can edit my first post?
 * Here is my code (simplified):
 *     ```
       <?php
       /*
       Template Name: Konf
       */
       ?>
       <?php
       $countobject1 = $_POST['object1'];
       if ($countobject1 == ''){
       	$countobject1 = '1';
       	}
       $countobject2 = $_POST['object2'];
       if ($countobject2 == ''){
       	$countobject2 = '1';
       	}
       $count_offn = $countobject1 + $countobject2;
       ?>
       .... etc. ...
       ```
   
 *  After that I get the page content (table via tablepress and the php extension).
   Within this table is written:
 * `<?php echo $count_offn; ?>`
 * In debug mode I get this error:
 * `Notice: Undefined variable: count_offn in /Applications/MAMP/htdocs/XXX/wp-content/
   plugins/tablepress-php-in-tables/tablepress-php-in-tables.php(26) : eval()'d 
   code on line 1`
 * Cheers & Thx
    bbthoms
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/php-variable-in-tablepress/#post-5646334)
 * Hi,
 * editing your first post is no longer possible, I think. Editing a published post
   in the forums is only allowed for up to an hour or so.
 * Ok, so in the table, the PHP code is
 *     ```
       <?php echo $count_offn; ?>
       ```
   
 * At that location, you will need to tell PHP to use the global variable, i.e.
 *     ```
       <?php echo $GLOBALS['count_offn']; ?>
       ```
   
 * or (if you prefer that syntax)
 *     ```
       <?php global $count_offn; echo $count_offn; ?>
       ```
   
 * Regards,
    Tobias
 *  Thread Starter [bbthoms](https://wordpress.org/support/users/bbthoms/)
 * (@bbthoms)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/php-variable-in-tablepress/#post-5646339)
 * Hi Tobias,
 * thank you for the fast reply. I tried the global but in the template file. Obviously
   it was the wrong place.
 * Thank you very much!
 * Cheers
    bb
 *  Plugin Author [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * (@tobiasbg)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/php-variable-in-tablepress/#post-5646345)
 * Hi,
 * no problem, you are very welcome! 🙂 Good to hear that this helped!
 * Best wishes,
    Tobias
 * P.S.: In case you haven’t, please [rate TablePress](https://wordpress.org/support/view/plugin-reviews/tablepress)
   here in the plugin directory. Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘PHP Variable in Tablepress’ is closed to new replies.

 * ![](https://ps.w.org/tablepress/assets/icon.svg?rev=3192944)
 * [TablePress - Tables in WordPress made easy](https://wordpress.org/plugins/tablepress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/tablepress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/tablepress/)
 * [Active Topics](https://wordpress.org/support/plugin/tablepress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/tablepress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/tablepress/reviews/)

## Tags

 * [global](https://wordpress.org/support/topic-tag/global/)
 * [php](https://wordpress.org/support/topic-tag/php/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * 5 replies
 * 2 participants
 * Last reply from: [Tobias Bäthge](https://wordpress.org/support/users/tobiasbg/)
 * Last activity: [11 years, 5 months ago](https://wordpress.org/support/topic/php-variable-in-tablepress/#post-5646345)
 * Status: resolved