/    Sign up×
Community /Pin to ProfileBookmark

Nightmare of a PHP problem

Hello all!

I have a PHP page that assigns a value to a variable named $gui_txt as a result of a SQL query.

What I am trying to do is create a link that will open a new web browser window and display the value of $gui_txt on that new window.

The code I have currently is a javascript function and PHP echo to create the link, something is going really wrong. It is displaying the value of the variable where the link is supposed to be.

Here is my code:

[CODE]<script language=”javascript” type=”text/javascript”>
function getGuidelines(which)
{
window.open(“http://localhost/guidelinestexttest.php?which_guidelines=” + ‘”‘ + which + ‘”‘);
}
</script>[/CODE]

Here is the echo code:

[CODE]echo”<a href=”javascript:getGuidelines(“$gui_txt”)”>Test</a>”;[/CODE]

I have also tried this echo code:

[CODE]echo”<a href=’#’ onclick=’getGuidelines(“$gui_txt”);’>Testing</a>”;[/CODE]

Neither work, the first echo code dumps all the variable data as some huge link that does nothing and the second echo code just appends a # at the end of the URL and goes to the top of the page.

I been struggling with this for hours…your help is greatly appreciated

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 30.2015 — How about this?
[code=php]
<?php
// code
?>
<a href="javascript:getGuidelines('<?php echo urlencode($gui_txt); ?>')">Test</a>
<?php
// more code
?>
[/code]
Copy linkTweet thisAlerts:
@NogDogApr 30.2015 — How about this?
[code=php]
<?php
// code
?>
<a href="javascript:getGuidelines('<?php echo urlencode($gui_txt); ?>')">Test</a>
<?php
// more code
?>
[/code]
Copy linkTweet thisAlerts:
@mikedcmdvaauthorApr 30.2015 — How about this?
[code=php]
<?php
// code
?>
<a href="javascript:getGuidelines('<?php echo urlencode($gui_txt); ?>')">Test</a>
<?php
// more code
?>
[/code]
[/QUOTE]


Thank you for that reply. It got me farther then I have been all day. I can see when I hover my mouse over the link, it is reflecting the variable. However, when I click the link, the browser does not do anything. I opened the JavaScript Console just for curiosity, and in red text I can see something that says "Uncaught SyntaxError: Unexpected token ILLEGAL"
Copy linkTweet thisAlerts:
@OmegaJuniorMay 01.2015 — NogDog's coding should be correct for echoing the identification into the link.

I suspect the javascript function to be the next cause for concern.

I would omit the quotes around the argument 'which', inside the window.open() statement.

Also, test your javascript coding in a compiler like Google Closure Compiler or JSLint. They can show you if there are any problems with your code that makes the browsers puke.
Copy linkTweet thisAlerts:
@NogDogMay 01.2015 — Good call by OmegaJunior: you should only need to concatenate in the variable -- it doesn't need to be quoted.
Copy linkTweet thisAlerts:
@mikedcmdvaauthorMay 01.2015 — Resolved!! ::wipes sweat from forehead::

Here is my working code:

&lt;a href="#" target="_blank" onClick="window.open('http://localhost/stuff/guidelinestexttest.php?which_guidelines=&lt;? echo urlencode($gui_txt) ?&gt;', 'targetWindow', 'toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=500, height=400')"&gt;Testing Link&lt;/a&gt;

Coming from an object oriented guy who mainly codes in C#, I must say, PHP is quite weird.
Copy linkTweet thisAlerts:
@NogDogMay 01.2015 — That's okay, I find Ruby to be weird. (Spent years getting this OOP stuff down, and then Ruby throws in "duck-typing". :rolleyes: )
×

Success!

Help @mikedcmdva spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...