Reputation: 65
Im trying to add a PHP variable to a href url
This is the code:
PHP
$uid= $_SESSION['userid'];
HTML
<a href=http://example.com/uid= <?php echo ".$uid."?> /a>
How do you add, when I do it, this is what it redirect too: http://example.com/uid=.
Upvotes: 2
Views: 35233
Reputation: 3897
You're doing a couple things wrong.
<?=
shorthand instead of <?php echo
<a /a>
is broken tag syntax. Should be <a>...</a>
End result is this:
<a href="http://example.com/uid=<?=$uid?>">Link Text</a>
Upvotes: 0
Reputation: 445
This is one of the most helpful
echo "<td>".($tripId != null ? "<a target=\"_blank\"href=\"http://www.rooms.com/r/trip/".$tripId."\">".$tripId."</a>" : "-")."</td>";
It will work!
Upvotes: 1
Reputation: 21
try this
<?php
$url = 'https://www.w3schools.com/php/';
?>
<a href="<?php echo $url;?>">PHP 5 Tutorial</a>
Or for PHP 5.4+ (<?= is the PHP short echo tag):
<a href="<?= $url ?>">PHP 5 Tutorial</a>
or
echo '<a href="' . $url . '">PHP 5 Tutorial</a>';
Upvotes: 1
Reputation: 987
echo "<a href=\"http://example.com/?uid=$uid\">link description</a>";
Upvotes: 2
Reputation:
Perhaps something like this:
print '<a href=http://example.com/?uid=' . $uid . '>Link</a>';
Upvotes: 1
Reputation: 411
This will work
<a href=http://example.com/?uid= <?php echo $uid ?> Myurl</a>
Upvotes: 0
Reputation: 22711
Try this,
<?php
@session_start();
$uid= $_SESSION['userid'];
?>
<a href="http://example.com/?uid=<?php echo $uid; ?>" >Your link text</a>
Upvotes: 8