Web Analytics Made Easy -
StatCounter Need Help with passing PHP database info to a Javascript src URL - CodingForum

Announcement

Collapse
No announcement yet.

Need Help with passing PHP database info to a Javascript src URL

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need Help with passing PHP database info to a Javascript src URL

    Hi all,

    I'm a newbie to coding in general (barely know enough to be dangerous), but I've created a company and decided to handle the integration myself. Now I realize I'm a bit over my head and can use a little help! I need to pass user info from my Wordpress database into a URL, then place that URL into an external Javascript link. I may not be explaining this well, so let me attempt to show my dilemma.

    Here's the PHP code to pull a users email address from my wordpress database:
    Code:
      <?php function getemail() {
    $current_user = wp_get_current_user();
       
        echo $current_user->user_email;
        }
    	?>
    This code calls the function and prints the email address:
    Code:
    <?php
    $func = 'getemail';
    $func(); ?>
    Now this is where I'm stuck, how would I get this email address to populate after the 'clientid=' portion of the following JavaScript src field? Would I have to rewrite with $_GET and create a custom url, then pass it on some other way?

    Code:
    <script language='JavaScript' src='[editedforsecurity]entrypoint.asp?p=1;email%40email.com;description;name;company&ref=name&clientid=company'> </script>
    Any help would be GREATLY appreciated. I really need to populate these fields automatically or I can't tell which customer I'm chatting with or track their individual tickets. Thank you in advance!
    Last edited by RWhit; Sep 1, 2011, 07:12 PM.

  • #2
    Originally posted by RWhit View Post
    This code calls the function and prints the email address:
    Code:
    <?php
    $func = 'getemail';
    $func(); ?>
    You shouldn't need to assign it to a variable like that. Just call getemail().
    Originally posted by RWhit View Post
    Now this is where I'm stuck, how would I get this email address to populate after the 'clientid=' portion of the following JavaScript src field? Would I have to rewrite with $_GET and create a custom url, then pass it on some other way?

    Code:
    <script language='JavaScript' src='[editedforsecurity]entrypoint.asp?p=1;email%40email.com;description;name;company&ref=name&clientid=company'> </script>
    It depends on the context you are outputting that line in. Assuming it's in an HTML block in a PHP page you could do something like this:
    PHP Code:
    <script language='JavaScript' src='[editedforsecurity]entrypoint.asp?p=1;email%40email.com;description;name;company&ref=name&clientid=<?php getemail(); ?>'> </script>

    Comment


    • #3
      Hey Inigo! Thanks for your response, you are correct in assuming that it is an HTML link. I've actually figured it out and am posting what I came up with here in case anyone else needs help parsing info into an HTML link between languages. I'm pretty sure that the code is sloppy, because I am a beginner, but it works! I'm still assigning the function to a variable only because for some reason typing getuserinfo() to call it wasn't working on my Wordpress site. Could be a conflict with an existing plug-in or even PEBKAC to be honest.

      Code:
      <?php function getuserinfo() {
      $current_user = wp_get_current_user();
      $Email = $current_user->user_email;
      $UserL = $current_user->user_login;
      $UserFN = $current_user->user_firstname;
      $UserLN = $current_user->user_firstname;
      //Build variable for NTR button
      $NTR_code = "<script language='JavaScript' src='[edited link]p=1;ref=$Email;description;ref=$UserFN&ref=$UserLN;company&ref=name&clientid=ref=$UserL'> </script>";
          
      
      print $NTR_code;
          }
      $func = 'getuserinfo';
      $func();?>
      Any constructive criticism is welcome. Enjoy!
      Last edited by RWhit; Sep 2, 2011, 01:54 PM.

      Comment

      Working...
      X
      😀
      🥰
      🤢
      😎
      😡
      👍
      👎