0

I'm trying to link several variables from a database into html. All the data is stored in the DB, however I can't figure out how to link the variables through HTML. Below is my code that I have tried, but doesn't work properly.

echo '<a href="' + $row["name"] +'">test</a>';

I know the code works properly if I just do something like this (it does return the name):

echo $row["name"];

So why doesn't it work properly with the + $row["name"] + in it? It works perfect as long as I don't try and add data with the +'s.

Thank you!

user1114503
  • 149
  • 2
  • 12

3 Answers3

2

this is the correct way to write this

echo '<a href="'.$row["name"].'">test</a>';
priya786
  • 1,804
  • 12
  • 11
  • Its right way to do it – Ramesh Murugesan Mar 02 '15 at 08:42
  • 2
    @nl-x I think, because the first post was `echo "test";` which wasn't related to the question at all! And the question was asked many times before already! And this answer doesn't explain anything – Rizier123 Mar 02 '15 at 08:44
  • 1
    Well that happens if someone tries to be the first to answer at all costs, even if it means answering with something completely irrelevant and editing afterwords – ksbg Mar 02 '15 at 08:46
0

Use a . in stead of +.

And on a sidenote, if the data in the db isn't yet escaped, also use htmlspecialchars() on $row["name"]

nl-x
  • 11,762
  • 7
  • 33
  • 61
0

Try like this.

echo "<a href='".$row['name']."'>test</a>";
Priyank
  • 3,778
  • 3
  • 29
  • 48
  • Really?!!! You posted the exact answer already! Here: http://stackoverflow.com/a/28805582/3933332 You just deleted it, because you had 3 downV on it or what?! – Rizier123 Mar 02 '15 at 08:48
  • @user1114503 this may work for you :) – Priyank Mar 02 '15 at 08:49
  • @Rizier123 no i added the wrong quotes,thats why i delete my answer and add new. – Priyank Mar 02 '15 at 08:51
  • Then I can tell you that there is a [edit](http://stackoverflow.com/posts/28805675/edit) button to edit you answer!, so that you not have to post every time a new one if you make a change! Oh wait! You already [knew that!](http://stackoverflow.com/posts/28669162/revisions), so... why didn't you edited your old answer? – Rizier123 Mar 02 '15 at 08:54
  • BTW: On SO we want answers which add some *value*, but this answer is also the same as this one: http://stackoverflow.com/a/28805503/3933332 So what *value* adds this answer here what the other one doesn't have?! – Rizier123 Mar 02 '15 at 09:00
  • While this may answer the question it’s always a good idea to put some text in your answer to explain what you're doing. Read [how to write a good answer](http://stackoverflow.com/help/how-to-answer). – Jørgen R Mar 02 '15 at 09:23