...

View Full Version : Need Help with passing PHP database info to a Javascript src URL



RWhit
09-02-2011, 01:09 AM
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:

<?php function getemail() {
$current_user = wp_get_current_user();

echo $current_user->user_email;
}
?>
This code calls the function and prints the email address:

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


<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!

Inigoesdr
09-02-2011, 05:02 AM
This code calls the function and prints the email address:

<?php
$func = 'getemail';
$func(); ?>

You shouldn't need to assign it to a variable like that. Just call getemail().

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?


<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:

<script language='JavaScript' src='[editedforsecurity]entrypoint.asp?p=1;email%40email.com;description;name;company&ref=name&clientid=<?php getemail(); ?>'> </script>

RWhit
09-02-2011, 07:49 PM
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.


<?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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum