php / sql - phpmyadmin binary value show on web page

0

IhaveadatabaseofbookseachbookhasitsISBN,titleetcandevenhasanimage,whichIuploadedinthedatabaseforeachbook.buttheproblemisthattheimagedoesnotappear,echoestheimagebutdoesnotactuallyappear(seethephotos).ThecodeI'musingtocallthedatabaseimageisasfollows:

<?phpinclude('config.php');$sql="SELECT * FROM books WHERE category='computing'";
$r=mysqli_query($conn, $sql);
?>
<html>
    <head>
    </head>
    <body>
<table cellpadding="2" cellspacing="2" border="0">
<tr>
    <th>ISBN</th>
    <th> Title </th>
    <th> Author's name</th>
    <th> edition</th>
    <th> year</th>
    <th> category</th>
    <th> publisher</th>
    <th> quantity-in-stock</th>
    <th> price</th>
</tr>

<?php while($books =mysqli_fetch_object($r)){?>
    <tr>
    <td> <?php echo $books->ISBN;   ?></td>
    <td> <?php echo $books->Title;  ?></td>
    <td> <?php echo $books->Authorsname; ?></td>
    <td> <?php echo $books->edition;?></td>
    <td> <?php echo $books->year;   ?></td>
    <td> <?php echo $books->category;   ?></td>
    <td> <?php echo $books->publisher;  ?></td>
    <td> <?php echo $books->quantityinstock; ?></td>
    <td> <?php echo $books->price; ?></td>
    echo '<img src="data:image/jpeg;base64,'.base64_encode( $books->Image ).'"/>';
    <td> <a href="shoppingcart.php?ISBN=<?php echo $books->ISBN; ?>">Order Now</a></td>
    </tr>
    <?php } ?>
</table>
    </body>
</html>

The base I'm using is phpmyadmin and it says "binary" please see the photo. Sorry if it's a basic question, but I'm new to this and I do not understand it very well.

Thank you

    
asked by anonymous 21.04.2017 / 19:01

1 answer

0

You made a small mistake when using the base64_decode function instead da base64_encode . The base64_encode function converts your image data to binary so it can be interpreted with MYME base64 by the browser.

Fixing stays:

echo '<img src="data:image/jpeg;base64,'.base64_encode( $books->Image ).'"/>';

When you used the base64_decode the browser could not interpret the content since it was not a valid base64.

    
21.04.2017 / 20:10