0

I'm trying to display product cards with images on my website, instead of the image, there's a text with symbols as below.

Here is the index:

$q = "SELECT * FROM items" ;
$r = mysqli_query( $link, $q ) ;
if ( mysqli_num_rows( $r ) > 0 )
{
  # Display body section.
  echo '';
  while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC ))
  {
    echo '
    <div class="product_wrapper">
    <a href="#"><img src='. $row['item_image'].' class="product_image"></a>
    <button class="addtocart_button"><a href="added.php?id='.$row['item_id'].'">Add to cart</button>
    <p class="product_details"><a href="item.html">'. $row['item_name'] . '
    <p class="product_details">' . $row['item_price'] . '
    <div class="star_container">
        &#9733; &#9733; &#9733; &#9733; &#9733;
    </div>
</div>
';
  }

And here is a small chunk of what's displayed on the website. The image is stored as 'BLOB' data type in PHPmyAdmin. After inserting it into database, I've noticed the following message: 'Linting is disabled for this query because it exceeds the maximum length'.

��� )���������_&?���YNO�5�ᶌ�#>٫'�L���i�Mϗ'���3Z���J��S�����ZKp{\C�0A�����c����Wn�/֨��?�U!�� 

I've edited the image line like so:

<a href="#"><img src="data:image/jpeg;base64,'. base64_encode($row['item_image']).' class="product_image"></a>

This got rid of the symbols, however, the image still doesn't display (small error image).

Daniel Klas
  • 37
  • 1
  • 5
  • You can't display the image as a text unless it is base64 encoded. How do you actually store the image in DB? How did you try to view it in VS code that you got this text? – Dharman May 12 '19 at 11:18
  • Using blob needs some optimization to give expected results. You should separate blob in different table and use join in your query also explore tutorials around on google this to make queries much better. – Creative87 May 12 '19 at 11:18
  • I've inserted the image through phpmyadmin, simply by choosing file and uploading it. I'm viewing the page with UwAmp. – Daniel Klas May 12 '19 at 11:19
  • It looks like you're missing a double quote (") before the ` class=` – nahanil May 12 '19 at 11:38
  • 1
    You've fixed for me nahanil! Such an overlook on my side, thank you! – Daniel Klas May 12 '19 at 11:46

1 Answers1

0

It looks like you're missing a double quote (") before the class= – nahanil

Daniel Klas
  • 37
  • 1
  • 5