Hi ive run into what I thought would be a simple obstacle however, its become quite a hassle I want to display a picture on my website however it will be different for every user that is logged in. I tried this
<img src="<?php echo 'screenshots/img_$username.png' ?>" />
I didnt really think that would work but Im not exactly sure where to go on this one I have a java application that saves the images to a file on the users computer then uploads them to my server and saves them all as "img_someusername.png" but the username is going to be different for every person
how can I get it so that the user that is logged in will see his or her picture and not someone else's much like a profile picture on facebook?
try this instead.
<img src="screenshots/img_<?php echo $username; ?>.png" />
<?php
echo "<img src='screenshots/img_".$username."'>";
?>
The problem is that you are trying to evaluate a PHP variable inside a single quote (') string. You can evaluate a variable only inside a double quote string ("). It should be fine to change your code to this, assuming the path of the image is correct.
<img src="<?php echo "screenshots/img_$username.png" ?>" />
Alternatively, the other two answers will also work. Lots of options in PHP.
If your string contains a a variable, it's better to use double quotes echo it. Here, I've enclosed the src attribute in single-quotes, and then the echo statement itself in double-quotes.
<img src='<?php echo "screenshots/img_{$username}.png" ?>' />
Alternative solution would be to concatenate the variable:
<img src="<?php echo 'screenshots/img_'. $username ; ?>" />
Hope this helps!
When your java program is being used, it automatically saves the image with an extension so perhaps you don't need to add an extension. Perhpas shawn.jpg or sandra.jpg.
This is what I would do.
<img src="<?php echo 'screenshots/img_'.$usernames; ?>" />
The other users have already mentioned ways in which .png can be added as well.
if not this would also work
<img src="<?php echo 'screenshots/img_'.$usernames.'.png'; ?>" />
Thanks.