Page 1 of 1

PHP snippet not working inside html background tag

Posted: Sat Jul 07, 2007 3:30 pm
by slade27
Hello,

I have a background image stored in a field called background and it shows up fine on a page using the following:

Code: Select all

echo $row['background'];
I have made various attempts to assign that variable as the background in an html table, but no matter what I try, the image will not show up. Here are some of the things I have tried that have not worked:

Code: Select all

echo "<td width='100%' background='".$row['background']."'>";

Then, I tried:

Code: Select all

$FixedBack = htmlentities($row['background']);

echo "<td width='100%' background='".$FixedBack."'>";

I also tried escaping php except for the variable itself:

<td width="100%" background="

Code: Select all

<?php echo $row['background'] ?>
">

Then finally I repeated the latter approach but after using the htmlentities function:

Code: Select all

$FixedBack = htmlentities($row['background']);

?>

<td width="100%" background="<?php echo $FixedBack ?>
">"


I'm a php newbie, however I'm puzzled because it seems to me that most of the ploys I've tried above have worked for me in other circumstances --
So thanks in advance for any ideas on what I'm doing wrong.

Brian

Posted: Sat Jul 07, 2007 3:37 pm
by superdezign
What do you get on-screen when you echo the background (without anything else... Just the background)?

Posted: Sat Jul 07, 2007 3:49 pm
by slade27
When I use the following, for example, the screen loads with the background image specified in the record in my database where the $ID = '4':

Code: Select all

$ID='4';


$sql="SELECT * FROM Articles WHERE ID LIKE '$ID'" ;
$result = mysql_query($sql);


while ($row = mysql_fetch_assoc($result)) {









echo $row['background'];

}

Follow-up info

Posted: Sat Jul 07, 2007 3:55 pm
by slade27
The actual background data stored in the database under the variable "background" looks something like this:

<body background="http://www.mysite.com/background/food.gif">

Oh

Posted: Sat Jul 07, 2007 3:58 pm
by slade27
In fact, I think just posting that last bit of info shows me the problem. I think my variable contains html code that is inappropriate for inclusion in the table html I'm trying to create.

Thanks, I think you've helped me see the problem just by requesting that info!

Brian

Posted: Sat Jul 07, 2007 4:00 pm
by superdezign
You're welcome. :P