-1

I'm trying to pass an id in a link href and I need it to be printed in the URL, my code is:

echo "<a href='ville.php?id='"echo.$ville_id."> $ville_nom </a>";

But the id is not print in the url, could you help me with the syntax ?

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
  • `echo "". $ville_nom ."";` I think there is a lot of question about this on SO – Sfili_81 Sep 17 '20 at 13:34
  • Does this answer your question? [PHP - concatenate or directly insert variables in string](https://stackoverflow.com/questions/5605965/php-concatenate-or-directly-insert-variables-in-string) – SeeoX Sep 17 '20 at 15:09

2 Answers2

1

You have mistake in your usage of echo and your concat was wrong.

The corrected code :

echo "<a href='ville.php?id='".$ville_id."'> $ville_nom "; 

When you used the double quote it's not necessary to concat variables to show their content. Be careful: it can be dangerous sometimes.

echo "<a href='ville.php?id=$ville_id'> $ville_nom "; 
TRiG
  • 10,148
  • 7
  • 57
  • 107
Inazo
  • 488
  • 4
  • 15
0

Try to use this:

echo "<a href='ville.php?id=" . $ville_id . "'>"
Obsidian
  • 3,719
  • 8
  • 17
  • 30