displaying an image in php from an xampp database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Emma17
    New Member
    • Mar 2012
    • 5

    displaying an image in php from an xampp database

    Ive written code in php and have managed to connect to the database and show all the information from it except the image (BLOB) file. This is the code so far.....

    Code:
    <?php
    
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die ('Could Not Connect:' . mysql_error());
    }
    
    mysql_select_db("membership",$con);
    
    $result = mysql_query ("SELECT * FROM members");
    
    echo "<table border='1'>
    <tr>
    <th> headers </th>
    <th> headers1 </th>
    <th> headers2 </th>
    <th> headers3 </th>
    <th> headers4 </th>
    </tr>";
    
    while ($row = mysql_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['photo'] . "</td>";
    echo "<td>" . <img src=\"members.php?file={$row["photo"]}\">" . "</td>";
    echo "<td>" . $row['headers'] . "</td>";
    echo "<td>" . $row['headers1'] . "</td>";
    echo "<td>" . $row['headers2'] . "</td>";
    echo "<td>" . $row['headers3'] . "</td>";
    echo "<td>" . $row['headers4'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";
    
    mysql_close($con);
    
    ?>
    How do I fix this please??
    Last edited by Dormilich; Mar 22 '12, 04:09 PM. Reason: Please use [CODE] [/CODE] tags when posting code.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    where is the code to display the image itself?

    Comment

    • Emma17
      New Member
      • Mar 2012
      • 5

      #3
      do i need that if the image is already stored in a database?
      I'm new to this and I don't quite understand how this works!!

      If all the information from the table displays on the page shouldn't the image do that to?
      It only displays like an icon of where the image would be....

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        do i need that if the image is already stored in a database?
        can a browser read a database directly?


        If all the information from the table displays on the page shouldn't the image do that to?
        which brings us to the question: how does HTML display an image?


        It only displays like an icon of where the image would be....
        answer 0.5: not like it displays text, obviously …

        Comment

        • Emma17
          New Member
          • Mar 2012
          • 5

          #5
          okay, well how can I fix it?

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            fix what?

            Comment

            • Emma17
              New Member
              • Mar 2012
              • 5

              #7
              it not displaying an image...... like am i missing code or have i done something wrong?

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                to start from the beginning, how do you (try to) display the image?

                Comment

                • Emma17
                  New Member
                  • Mar 2012
                  • 5

                  #9
                  i put an <img src> tag in a row

                  Comment

                  • Niheel
                    Recognized Expert Moderator Top Contributor
                    • Jul 2005
                    • 2432

                    #10
                    The data in $row['photo'] is a blob, it isn't an image, you can't output it. You have to take that data and then either create a script that will output it as an image, or you can write it to a file. It is data that is most likely binary(images).

                    Read up on how to create image files with blob data in database.
                    niheel @ bytes

                    Comment

                    • helimeef
                      New Member
                      • Sep 2007
                      • 77

                      #11
                      Well, another potential problem would be that you don't have an opening quote before your <img> tag:

                      Code:
                      echo "<td>" . <img src=\"members.php?file={$row["photo"]}\">" . "</td>";

                      Should read:

                      Code:
                      echo "<td>" . "<img src=\"members.php?file={$row["photo"]}\">" . "</td>";

                      Comment

                      Working...