I retrieve an image from the database with php and then I want to use this image in html
as a background.
I try to use this code, but it doesn't work:
<div class="fill" style="background-image:url('<?php echo "<img src='getImg.php?id=$13'>"; ?>');"></div>
Rajdeep Paul is correct the variable is invalid also
your syntax for the css is incorrect:
<div class="fill" style="background-image:url('<?php echo "getImg.php?id=$X13" ?>')"></div>
no <img src
...
Your background-image:url
syntax and variable
name are incorrect , try the folowing:
<?php
echo "<div class='fill' style=\"background-image:url('getImg.php?id=$VALIDVARIABLE')\"></div>";
Rules for PHP variables:
$
sign, followed by the name of the variable Az
, 0-9
, and _
) $age
and $AGE
are two different variables) Try this:
<?php $url = require("path/to/getImg.php?id=".$13;); ?>
<div class="fill" style="background-image:url('<?php echo $url; ?>');"></div>
I am not sure about this line:
<?php $url = require("path/to/getImg.php?id=".$13;); ?>
But the value what you need to use on the background-image:url('anything') is not a img tag... sure. You need to put the url to the image.
I hope it helps you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.