James
James

Reputation: 161

Incorporating php variable into url with href attribute

I am trying to create the necessary url from this code however it is working and I am struggling to find out why.

$linkere = $row['message'];
echo '<a href="me.php?message=<?php echo rawurlencode($linkere); ?>">'

Currently this code is producing the url: me.php?message= . But, I would like it to create the url: me.php?message=hello for example.

Thanks for helping!

Upvotes: 0

Views: 97

Answers (4)

the_pete
the_pete

Reputation: 822

You don't need the <? ?> and echo in your echo, it should just be:

$linkere = $row['message'];
echo '<a href="me.php?message='.rawurlencode($linkere).'">Test</a>';

Otherwise you are turning php on and off again to echo something within an already open instance of php in which you are already echoing.

Upvotes: 0

Krish R
Krish R

Reputation: 22711

Can you try this,

 $linker = $row['message'];
 echo '<a href="me.php?message='.rawurlencode($linker).'">YOUR LINK TEXT HERE</a>';

Upvotes: 0

Jorge Faianca
Jorge Faianca

Reputation: 791

You have alot of syntax problems here.

first, you need to use Concatenation message='.rawurlencode($linker).'" second your variable do not exist, it should be $linker.

Second close the tag and insert the text, in this case i used Test.

$linker = $row['message'];
echo '<a href="me.php?message='.rawurlencode($linker).'">Test</a>';

Upvotes: 0

John Conde
John Conde

Reputation: 219804

You are passing $linkere to rawurlencode(). The variable is actually named $linker.

$linker = $row['message'];
echo '<a href="me.php?message=<?php echo rawurlencode($linker); ?>">'

Upvotes: 2

Related Questions