PHP snippet not working inside html background tag

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slade27
Forum Newbie
Posts: 21
Joined: Tue Apr 24, 2007 3:49 am

PHP snippet not working inside html background tag

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

What do you get on-screen when you echo the background (without anything else... Just the background)?
slade27
Forum Newbie
Posts: 21
Joined: Tue Apr 24, 2007 3:49 am

Post 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'];

}
slade27
Forum Newbie
Posts: 21
Joined: Tue Apr 24, 2007 3:49 am

Follow-up info

Post 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">
slade27
Forum Newbie
Posts: 21
Joined: Tue Apr 24, 2007 3:49 am

Oh

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You're welcome. :P
Post Reply