Title: &#8216;Insert php, can&#8217;t pass its variable to Rawjs
Last modified: November 13, 2018

---

# ‘Insert php, can’t pass its variable to Rawjs

 *  [world2026](https://wordpress.org/support/users/world2026/)
 * (@world2026)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/insert-php-cant-pass-its-variable-to-rawjs/)
 * Hello, I’m having problem passing PHP variable to javascript(Rawjs).
 * I’ve successfully got data from Mysql and display in HTML .
 * But my main goal is to assign the data to js variable. Computed like this
 * Rawjs
 *     ```
       [wbcr_php_snippet id="8091"]
       <script>
       var b="[wbcr_php_snippet id="8101"]";
       </script>
       ```
   
 * wbcr_php_snippet id=”8091″]
 *     ```
       $query= "select meta_value from wp_gf_entry_meta where meta_key=38";
   
       if ($result = mysqli_query($conn, $query)) {
   
           while ($row = mysqli_fetch_array($result)) {
               $getii = $row[0];      
           }
         mysqli_free_result($result);
       }
       ```
   
 * [wbcr_php_snippet id=”8101″]
    `echo $getii;`
 * Have done a lot of research but cant figure out why `var b` in Rawjs always get
   0
    -  This topic was modified 7 years, 6 months ago by [world2026](https://wordpress.org/support/users/world2026/).
    -  This topic was modified 7 years, 6 months ago by [world2026](https://wordpress.org/support/users/world2026/).

Viewing 1 replies (of 1 total)

 *  Plugin Author [webcraftic](https://wordpress.org/support/users/webcraftic/)
 * (@webcraftic)
 * [7 years, 6 months ago](https://wordpress.org/support/topic/insert-php-cant-pass-its-variable-to-rawjs/#post-10897912)
 * Hi,
 * You can use js code directly inside the snippet.
 * See example:
 *     ```
       $query= "select meta_value from wp_gf_entry_meta where meta_key=38";
   
       if ($result = mysqli_query($conn, $query)) {
   
           while ($row = mysqli_fetch_array($result)) {
               $getii = $row[0];      
           }
         mysqli_free_result($result);
       }
       ?>
       <script>
       var b="<?=$getii?>";
       </script>
       ```
   
 * Please check your php code so that the $getii variable has the value you need.
 * If you are trying to use the shortcode in double-quotes, this can cause problems.
   You need to escape double quotes inside the shortcode so that you have no problem
   with that.
 * Best regards, Alex

Viewing 1 replies (of 1 total)

The topic ‘‘Insert php, can’t pass its variable to Rawjs’ is closed to new replies.

 * ![](https://ps.w.org/insert-php/assets/icon-256x256.gif?rev=3523853)
 * [Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts](https://wordpress.org/plugins/insert-php/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/insert-php/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/insert-php/)
 * [Active Topics](https://wordpress.org/support/plugin/insert-php/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/insert-php/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/insert-php/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [webcraftic](https://wordpress.org/support/users/webcraftic/)
 * Last activity: [7 years, 6 months ago](https://wordpress.org/support/topic/insert-php-cant-pass-its-variable-to-rawjs/#post-10897912)
 * Status: not resolved