Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2011
    Posts
    24
    Thanks
    3
    Thanked 0 Times in 0 Posts

    CSS style written by PHP doesn't work!

    Hi, experts, help please, thank you so much.

    I wrote css style for an image by PHP, as follows:

    <img src="<?php echo "/images/prizes/".$_SESSION['imgForPrizes'][$key1]; ?>" >

    It's working , and fine.


    However, if I want the image as a background, and wrote as below:

    <.... style="background:url(“<?php echo “/images/prizes/”.$_SESSION['imgForPrizes'][$key1]; ?>”) no-repeat center; ">

    It's not working, the image doesn't show on the web page.

    Could experts help me to sort the problem out?

    Thank you!
    Last edited by sam9461; 01-20-2012 at 01:09 AM.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,462
    Thanks
    0
    Thanked 633 Times in 623 Posts
    Are the invalid characters in “<?php echo “/images/prizes/”.$_SESSION['imgForPrizes'][$key1]; ?>” actually there or are they really " that have been accidentally converted to invalid characters when you copied them to the forum?

    If they are actually " and not invalid angled quotes then have you tried viewing the source of the page to see what code is being generated by the PHP when someone views the page?
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    sam9461 (01-20-2012)

  • #3
    New Coder
    Join Date
    Jul 2011
    Posts
    24
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Felgall, thanks,

    I've sort it out, by removing " " between ( and <, then it is working.



    <.... style="background:url(<?php echo “/images/prizes/”.$_SESSION['imgForPrizes'][$key1]; ?>) no-repeat center; ">


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •