Display an image from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hanspeare
    New Member
    • May 2014
    • 20

    Display an image from database

    Hello everyone,

    I want to display an image on the webpage which was uploaded and stored in the database.

    Here is my HTML codes
    Code:
    <img src="getImage.php?id={$student_id} <?php echo $data["LRCard"]?>;" width="175" height="200" />
    and here is my getImage.php codes

    Code:
    <?php
      include 'Connect.php';
      mysql_select_db("student");
      $id = $_GET['id'];
      $student_id = htmlentities($_REQUEST['id'], ENT_QUOTES);
      $result = mysql_query("SELECT LRCard FROM student_information where student_id='$_GET[id]'");
      $row = mysql_fetch_assoc($result);
      $row = mysql_fetch_object($result);
      mysql_close($link);  
        
      header("Content-type: image/jpeg");
      header("Content-type: image/gif");
      echo $row['LRCard'];
    ?>
    The image won't display :-(
    Please anyone here can help me modify this codes.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    The image won't display
    of course not. your own code duplicates getting in your way. deleting lines #4, #5 & #8 should help as a quick’n’dirty fix.

    nevertheless, you’re still susceptible to SQL Injection and you use the deprecated mysql functions.

    Comment

    • hanspeare
      New Member
      • May 2014
      • 20

      #3
      Hi Dormilich,

      I have followed your advise but it still doesn't display. The dimension is there but the picture is broken.


      nevertheless, you’re still susceptible to SQL Injection and you use the deprecated mysql functions.


      What do you mean by this? Please advise.
      Last edited by hanspeare; May 20 '14, 12:36 PM. Reason: supposedly not code but qoute

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        nevertheless, you’re still susceptible to SQL Injection and you use the deprecated mysql functions.
        What do you mean by this? Please advise.
        see http://en.wikipedia.org/wiki/Sql_injection and http://php.net/mysql-query.
        Last edited by Dormilich; May 20 '14, 01:34 PM.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          load getImage.php?id =<enter-valid-id-here> in the address bar and check if there are any error messages.

          Comment

          • hanspeare
            New Member
            • May 2014
            • 20

            #6
            Hi Dormilich,

            It shows no error but a broken image on the upper right.
            What does it signifies?

            Comment

            • hanspeare
              New Member
              • May 2014
              • 20

              #7
              Thanks i will check that link im sure it will add to my learnings.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                What does it signifies?
                the image data are incorrectly parsed.

                possible reasons:
                - wrong header (a gif image with a jpeg MIME header won’t display)
                - additional text data before, inside or after the binary image data
                - the binary image data itself are corrupted

                Comment

                • hanspeare
                  New Member
                  • May 2014
                  • 20

                  #9
                  so does it mean there is nothing wrong woth my codes or i need to add some headers or modified it?

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    I don’t know your current code, I don‘t know what you have saved in your DB, I don’t know what headers you receive or what are necessary, I don’t know if there are any errors (reported).

                    If I have this information, I can give you an answer.

                    Comment

                    Working...