-2
 $imagefilename=$row['uimage']; 

i.e storing the url of an image from table to variable imagefilename

now i wish to use that file name and fetch the image from its location by using the command

 echo '<a href="update/update.php"><img id="unregistered" src="php/customer/customer_images/{$imagefilename}"/></a>';

but its not considering "$imagefilename" as a part of the url could some one please tell me how to make this happen thanks!

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Faize Shan
  • 13
  • 3
  • 1
    You need to use `"` instead `'` or you write it like this `echo 'sometext'.$var.'someothertext';` – Spirit Dec 13 '18 at 06:29
  • Depending on the circumstances, you might also be able to only inject the variable into your actual HTML: `` – domsson Dec 13 '18 at 06:53

3 Answers3

2

Append the php variable using single quote like below:

echo '<a href="update/update.php"><img id="unregistered" src="php/customer/customer_images/'.$imagefilename.'/></a>';
lifeisbeautiful
  • 817
  • 1
  • 8
  • 18
  • bhat i tried your code but there is one little bug "http://localhost/AirBnb/php/customer/customer_images/IMG-20140414-WA0000.jpg/%3E%3C/a%3E%3Ca%20href=" in my db the value stored is only "IMG-20140414-WA0000.jpg" but its adding /%3E%3C/a%3E%3Ca%20href= extra i dono where it comes from can you help me please – Faize Shan Dec 13 '18 at 06:43
  • 2
    Try `urldecode()` source: http://php.net/manual/de/function.urldecode.php – Spirit Dec 13 '18 at 06:46
  • Yes as suggested by @Spirit. Try that it will work – lifeisbeautiful Dec 13 '18 at 06:53
  • @AravindBhatK could you please tell how to include that urldecode() in the src double quotes – Faize Shan Dec 13 '18 at 07:01
  • @Spirit could you please tell how to include that urldecode() in the src double quotes – Faize Shan Dec 13 '18 at 07:02
  • 1
    Try like this: echo ' – lifeisbeautiful Dec 13 '18 at 07:15
  • You can use the option from @AravindBhatK or work with a lambda function: `$myfunc = function($text) { echo urldecode($text); }; echo "somtext{$myfunc($var)}";` – Spirit Dec 13 '18 at 08:13
0

TRY THIS

  <?php
$imagefilename = "file1.jpg";
   echo '<a href="update/update.php"><img id="unregistered" src="php/customer/customer_images/'.$imagefilename.'/></a>';

   echo "\n";

   echo "OR";

   echo "\n";

   $imagefilename = "php/customer/customer_images/file1.jpg";

   echo "https://localhost/folderName/update/update.php?$imagefilename";
?>
0

Here all the Comments in one Answer:

//Your image url
$var = 'my%20text';

// echo with ' and urldecode
echo 'sometext '.urldecode($var).' someothertext';

//lambda function with urldecode
$myfunc = function($text) {
    echo urldecode($text);
};

// working echo with {} (needs lambda function)
echo "somtext{$myfunc($var)}";
Spirit
  • 631
  • 7
  • 11