-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
  • 53,991
  • 11
  • 38
  • 52
  • `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
  • 9,687
  • 6
  • 54
  • 105
Inazo
  • 449
  • 4
  • 12
0

Try to use this:

echo "<a href='ville.php?id=" . $ville_id . "'>"
Obsidian
  • 3,195
  • 8
  • 16
  • 28