Results 1 to 5 of 5

Thread: Really simply image problem

  1. #1
    Join Date
    Jul 2007
    Location
    England
    Posts
    41
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question Really simply image problem

    What I need to do is display an image on the page, but part of the URL of that image comes from a PHP variable.

    Example- I want to display this image:

    http://website.com/images/$name/file.gif

    This is the code I have so far:

    Code:
    <?php
    $name = $_POST[name];
    ?>
    <img scr = "http://website.com/images/$name/file.gif">
    But it doesn't work. I know the problem is with the image insertion as the $name = $_POST[name]; works fine.

    Thanks in advance for your help.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    PHP Code:
    <?php
    $name 
    $_POST[name];
    ?>
    <img scr = "http://website.com/images/<?php echo $name?>/file.gif">
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    There is also a problem with the syntax of $_POST[name]: you should be using $_POST["name"] or $_POST['name']. I'm actually surprised it works without that.


    (In theory $_POST[name] would be proper syntax if name were defined as a constant, but that is unlikely here, especially because $_POST is an array of input data, not data you are creating yourself.)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by djr33 View Post
    There is also a problem with the syntax of $_POST[name]: you should be using $_POST["name"] or $_POST['name']. I'm actually surprised it works without that.
    Good point. I'm still such a newb at PHP, but I at least thought I had this one. However, it has generally been my experience in PHP that quotes aren't always required in the same way that they would be in javascript. This may or may not be one of those cases.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Correct-- this is parsed properly (apparently), but it is not proper code.

    But, yes, you solved why it wasn't displaying the image.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

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