-2

New to php and i have tried what I thought would work but it didnt work. I have an image in my upload folder name 1002386235.png the number 1002386235 is the user id and I would like to display a profile picture of the user with the help of php. With this I can display the image. What I am trying to achieve is replace the 1002386235.png with something like $uid.png, $uid being a variable with the user id in it. I thought the following would work but it didnt

<?php

$uid = "1002386235";

?>



<img src="upload/".$uid.".png">
David Mugo
  • 1
  • 1
  • 4
  • 1
    Just a little search : https://stackoverflow.com/questions/2150238/php-variable-in-html-no-other-way-than-php-echo-var – Danial Aug 15 '21 at 10:00
  • https://stackoverflow.com/questions/6130596/using-php-variables-inside-html-tags – Danial Aug 15 '21 at 10:00
  • 1
    Does this answer your question? [Using PHP variables inside HTML tags?](https://stackoverflow.com/questions/6130596/using-php-variables-inside-html-tags) – Danial Aug 15 '21 at 10:00

1 Answers1

1

You need to wrap the variable $uid within php tags and since your html is not inside php tags, the concatenation dot operators are not required. Also, you need to echo the variable inside your html.

Change this line:

<img src="upload/".$uid.".png">

To this:

<img src="upload/<?php echo $uid; ?>.png">
AndrewL64
  • 15,794
  • 8
  • 47
  • 79