amjad amjad - 9 months ago 52
HTML Question

using background-image with php

I retrieve the images from the database by php
and then I want use this image in

like background
I try to write this code but it is not work

<div class="fill" style="background-image:url('<?php echo "<img src='getImg.php?id=$13'>"; ?>');"></div>

When I just use php it's work, but in this waye does not work


Your background-image:url syntax and variable name are incorrect, try the folowing:

echo "<div class='fill' style=\"background-image:url('getImg.php?id=$VALIDVARIABLE')\"></div>";

Rules for PHP variables:

  1. A variable starts with the $ sign, followed by the name of the variable
  2. A variable name must start with a letter or the underscore character
  3. A variable name cannot start with a number
  4. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  5. Variable names are case-sensitive ($age and $AGE are two different variables)