#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    56
    Rep Power
    2

    How to echo an image in php with mysqli


    Hi,

    I am re-writing my code from mysql to mysqli, but I am not being able to echo images whose names are saved into a database while the images are saved in a folder named "images".

    I have the following code:


    echo "<td valign=top>\n

    <table width=150 border=1 align=left class=allborder> \n
    <tr> \n
    <td width=70>$row[1]</td> \n
    </tr>\n

    <tr> \n
    <td><img src=\"./images/$row[15]\" width=\"90\" height=\"120\" alt=\"\" /></a> \n
    </td>
    </tr>\n

    </table>\n</td> \n ";


    I have checked to ensure the field (cfilename) in the table is actually in row 15. I am not getting any error, just a blank with no image. On row [1] is a title which shows properly.

    How should i do this?

    Joseph
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,007
    Rep Power
    9398
    Can you do us a quick favor? You probably clicked the PHP code button and pasted the code in the dialog it popped up. Thing is that dialog doesn't work so well. Edit your post, delete everything in between the [php] tags, then re-paste your code back in. And next time you have code, paste your code into the textarea, select it, then hit the button.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    and please do some basic debugging yourself. Make a var_dump($row) to check the actual content of $row (and post it here).

    By the way, you should definitely fetch associative arrays (fetch_assoc) rather than fumbling with column indices.

    Last but not least, do not output raw values.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    56
    Rep Power
    2

    Thumbs up


    Originally Posted by Jacques1
    Hi,

    and please do some basic debugging yourself. Make a var_dump($row) to check the actual content of $row (and post it here).

    By the way, you should definitely fetch associative arrays (fetch_assoc) rather than fumbling with column indices.

    Last but not least, do not output raw values.
    Thanx. Everything is fine now.

    Stay well.

    Joseph
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    In stead of echo'ing out everything.. you should just write it in HTML and insert the php where needed

    PHP Code:
    <tr><td><img src="<?= $row[15?>" /></td></tr>
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    56
    Rep Power
    2
    Originally Posted by notflip
    In stead of echo'ing out everything.. you should just write it in HTML and insert the php where needed

    PHP Code:
    <tr><td><img src="<?= $row[15?>" /></td></tr>
    Thank you for that correction. I am learning alot from here.

    Stay well.

    Joseph
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Originally Posted by notflip
    PHP Code:
    <tr><td><img src="<?= $row[15?>" /></td></tr>
    It's still not escaped.

    And I think those short tags are obsolete. In any case, they require fumbling with the php.ini, so I don't think this is a good idea.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  14. #8
  15. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,317
    Rep Power
    7170
    And I think those short tags are obsolete.
    Yeah, that's actually a somewhat complicated matter. Best to just avoid them for right now.

    Until PHP 5.1, short tags were enabled by default.
    From PHP 5.1-5.3, short tags were disabled by default.
    From PHP 5.4+, short tags are still disabled by default, but <?= ?> is no longer considered a short tag (it works even when short tags are turned off).

    My guess: short tags will be removed at some point after PHP 5.5, but <?= ?> will remain and always be enabled.

    Since most people are running either PHP 5.2 or 5.3 right now, it's best to avoid <?= ?> for a few more years and it's definitely best to avoid <? ?>.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo