php in my html link doesn't work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
soundengine
Forum Newbie
Posts: 2
Joined: Sat Apr 25, 2009 2:49 pm

php in my html link doesn't work

Post by soundengine »

Hi everyone, I am trying to echo a variable within a plain html link, but it doesn't work. My link looks like this:

Code: Select all

<a href="xxxxxxx.myurl.net/?tid=<?php echo $var; ?>">some text here</a>
I know that php is running because when I use this on it's own:

Code: Select all

<?php echo $var; ?>
it displays the value of my variable $var, but it doesn't work in my link. I am new to php, and I have a feeling that there is some setting on my Apache Linux server that is set incorrectly. Perhaps in my setup file. You can see my php setup here - http://www.stephenpanderson.com/phpinfo.php

When I mouseover the link I see the link containing the php code unprocessed. I should be seeing the value instead.

when I view the source of my page the end of my link looks like this:

Code: Select all

.net/?tid=%3C?php%20echo%20$var;%20?%3E
Any help would be very appreciated. I am a beginner with php.

Thanks,
Steve
MasterBeta
Forum Commoner
Posts: 38
Joined: Thu Apr 02, 2009 4:35 am
Location: Lincoln, NE

Re: php in my html link doesn't work

Post by MasterBeta »

Strange.
What happens if you try this.

Code: Select all

<?php echo "<a href=\"xxxxxxx.myurl.net/?tid=$var\">some text here</a>"; ?>
soundengine
Forum Newbie
Posts: 2
Joined: Sat Apr 25, 2009 2:49 pm

Re: php in my html link doesn't work

Post by soundengine »

The php link works that you showed me, thanks. But how can I figure out what's wrong with my regular html url with just the php variable? I know that others are using that format and it's working for them.

Any ideas?
MasterBeta
Forum Commoner
Posts: 38
Joined: Thu Apr 02, 2009 4:35 am
Location: Lincoln, NE

Re: php in my html link doesn't work

Post by MasterBeta »

Somehow your opening php tag "<?php" is not being recognized. Make sure you are using valid html. http://validator.w3.org/.
I doubt there is a problem with your php configuration though. I'm not really sure. Good luck!
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: php in my html link doesn't work

Post by McInfo »

soundengine wrote:You can see my php setup here - http://.../phpinfo.php
A gift to crackers everywhere, that is.

Edit: This post was recovered from search engine cache.
Post Reply