conan318 Posted August 10, 2011 Share Posted August 10, 2011 Hi i am trying to write a small script to change the background img from my admin small panel i am making im not getting errors nor is the background img for my content changing. if i echo $background it display the img url correctly. can anyone see what where its going wrong thanks again $background; $data = mysql_query("SELECT * from main.background ORDER BY id DESC LIMIT 1;") or die(mysql_error()); //Puts it into an array while($info = mysql_fetch_array( $data )) { $background='img/'.$info['img']; // have also tryed $background="img/".$info['img']; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <LINK REL="SHORTCUT ICON" HREF="img/fav.png"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link href="mb.css" rel="stylesheet" type="text/css" /> <title>Mongrel Bastards</title> </head> <body> <style type="text/css"> .content{ background-image:url('<?php $background ?>'); height:2500px; width:1008;} </style> Quote Link to comment https://forums.phpfreaks.com/topic/244403-php-to-change-background-image/ Share on other sites More sharing options...
trq Posted August 10, 2011 Share Posted August 10, 2011 If $background echo's correctly your issue is nothing to do with the php. Your <style> element is within the <body> of your markup. ps; You don't need any while loop if your only expecting 1 result. Quote Link to comment https://forums.phpfreaks.com/topic/244403-php-to-change-background-image/#findComment-1255243 Share on other sites More sharing options...
cssfreakie Posted August 10, 2011 Share Posted August 10, 2011 although your missing that correct echo background-image:url('<?php $background ?>'); should be background-image:url('<?php echo $background; ?>'); Quote Link to comment https://forums.phpfreaks.com/topic/244403-php-to-change-background-image/#findComment-1255244 Share on other sites More sharing options...
conan318 Posted August 10, 2011 Author Share Posted August 10, 2011 is the style element meant to be in the head of the document cause i have tryed it there with no luck either. if i add the image in css file it works fine. but for some reason i cant embed it. strange Quote Link to comment https://forums.phpfreaks.com/topic/244403-php-to-change-background-image/#findComment-1255245 Share on other sites More sharing options...
cssfreakie Posted August 10, 2011 Share Posted August 10, 2011 is the style element meant to be in the head of the document cause i have tryed it there with no luck either. if i add the image in css file it works fine. but for some reason i cant embed it. strange did you try to echo as showed above?? Quote Link to comment https://forums.phpfreaks.com/topic/244403-php-to-change-background-image/#findComment-1255246 Share on other sites More sharing options...
conan318 Posted August 10, 2011 Author Share Posted August 10, 2011 ahhh the echo did the trick thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/244403-php-to-change-background-image/#findComment-1255247 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.