0

I'm trying to pass the value of a variable called artID with href, but I'm having trouble with exactly how and where to type it. When I type it outside the PHP tags, it makes a broken link, but doesn't make a link at all when it's inside the php tags..

<?php
"<a href='localhost/blog/article.php?artID='$artID>";

"<a>";
?>
0

5 Answers 5

2

Try it with this:

  <a href="localhost/blog/article.php?artID=<?php echo $artID; ?>">Article</a>

The reason why your code isn't working is because you don't echo your variable, your HTML is wrong and you forgot to add a single quote.

Sign up to request clarification or add additional context in comments.

1 Comment

try your code in your personal computer? its so wrong, missed quote in php and html attribute !
1

Try this :

<?php
echo "<a href='localhost/blog/article.php?artID=" . $artID . "'>";
echo "click me";
echo "</a>";
?>

1 Comment

echo "</a>"; at the end there.
0

Try doing something like:

<?php
echo "<a href='localhost/blog/article.php?artID='" . $artID . ">Click me</a>"
?>

this is assuming you have defined the variable and assigned its value.

Comments

0
<?php
echo "<a href='localhost/blog/article.php?artID='" . $artID . ">LINK</a>";
?>

Comments

0

Outside of PHP tags, the webserver won't know the value of your variable. Inside the PHP tags, you need to echo the string...Either:

<?php
echo "<a href=\"localhost/blog/article.php?artID=$artID\">";

echo "<a>";
?>

Or

<a href="localhost/blog/article.php?artID=<?php echo $artID ?>"</a>

should work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.